Jump to content

  • Log In with Google      Sign In   
  • Create Account

Make perspective appear ortho?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 slicer4ever   Crossbones+   -  Reputation: 3901

Like
0Likes
Like

Posted 13 March 2013 - 12:08 PM

so, here's what i want to do:

I have an picture, i split it into a 10 x 10 grid, I then randomly move these tiles back/forward along the z axis.  What i want to achieve is when the camera is looking down the z axis, the picture would look like it was in an ortho projection.

 

basically, what i need to know, is how to translate each tiles size and position, so that they perfectly align to a picture from only the one perspective.

 

also, i plan to rotate each tile to face the camera, i'm assuming to make this work, each tile well have to have a slight offset for looking at the camera, otherwise when i do align the camera in that one spot, all the tiles well be slighlty mis-aligned since their trying to look at the center point.

 

anyway, i need some pointers, the only thing i've found on this is: http://stackoverflow.com/questions/6962992/orthographic-to-perspective-adjustment-calculation but I can't figure out how to apply the information.  I'm assuming it's because i'm not taking into account the view matrix?

 

right now i'm not worrying about rotating the camera, or rotating the tiles to face the camera, so my first step is trying to figure out how to make the tile's align and size correctly.


Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

Sponsor:

#2 metsfan   Members   -  Reputation: 654

Like
0Likes
Like

Posted 13 March 2013 - 04:24 PM

Billboarding will solve the problem on making sure the tiles always face the camera.  A quick web search should provide you with plenty of information on billboarding techniques.   

 

The main question that's going through my head right now:  Why are you not just using an orthographic projection for the tiles, and a perspective projection for everything else?  There is nothing illegal about having mutliple projection matrices (for instance, games can render the game world using a perspective projection, and the game UI or HUD using an ortho projection).



#3 slicer4ever   Crossbones+   -  Reputation: 3901

Like
0Likes
Like

Posted 13 March 2013 - 04:37 PM

Billboarding will solve the problem on making sure the tiles always face the camera.  A quick web search should provide you with plenty of information on billboarding techniques.   

 

The main question that's going through my head right now:  Why are you not just using an orthographic projection for the tiles, and a perspective projection for everything else?  There is nothing illegal about having mutliple projection matrices (for instance, games can render the game world using a perspective projection, and the game UI or HUD using an ortho projection).

Billboarding does not suit this problem, as the goal is that at one particular camera angle, the image is absolutely perfect, this means each tile needs to be appropiatly positioned, and scaled, so the result is as if it were an ortho projection.  also mate, i completely understand that i can change matrix's at will, this is not a hud element, this is simply an illusion that is absolutely critical mechanic for my gameplay.


Edited by slicer4ever, 13 March 2013 - 04:38 PM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#4 Brother Bob   Moderators   -  Reputation: 8250

Like
0Likes
Like

Posted 13 March 2013 - 05:32 PM

At the depth Z of the perspective view frustum, the total range of the frustum is +/- tan(fov/2*Z), where fov is the field of view. Keep in mind that the vertical and horizontal FOV is different unless the aspect ratio is unity so make sure you take that into account; hfov=2*atan(aspect*tan(vfov/2)).

 

So, based on this, you can get the horizontal and vertical range at any depth of the perspective view. Split that range up into your 10x10 grid to figure out a specific grids corners at any depth.



#5 slicer4ever   Crossbones+   -  Reputation: 3901

Like
0Likes
Like

Posted 13 March 2013 - 07:53 PM

alright, so i've been playing with this, i do believe i understand the concept.

 

first off i've reduced the problem to a 3x3 grid to make life a bit easier, now basically, my thought process is this, get the vertical ratio of the perspective camera, and the  horizontal ratio.  I know that the image should appear as it is when the each tile's z axis is 0, which is 60 units from the camera.  so what i've been first trying to achieve is making the tile's center align(i don't care about resizing the tile's at the moment.)  I moved one tile(directly above the center tile) by 10 units toward the camera, this is what my code looks like at the moment:

 

 

            Vector2 PartDistance = new Vector2(TotalWidth/m_Width, TotalHeight/m_Height);
            Vector2 UpperLeft   = new Vector2(-30.0f, -30.0f)+PartDistance*0.5f;
            float vRatio = FMath.Tan(FMath.PI*0.175f); //get my FOV ratio which Math.PI*0.35(63 degrees) * 0.5
            Console.WriteLine("vRatio: "+vRatio);
            int Target = 1;
            for(int x=0;x<m_Width;x++){ //m_Width = 3
                for(int y=0;y<m_Height;y++){ //m_Height = 3
                    int Tile = x+y*m_Width;
                    Vector3 Center = new Vector3(UpperLeft.X+x*PartDistance.X, UpperLeft.Y+y*PartDistance.Y, (Tile==Target)?10.0f:0.0f);
                    float vRat = Center.Z==0.0f?1.0f: vRatio*Center.Z;
                   
                    Vector3 NewCtr = new Vector3(Center.X, Center.Y*vRat, Center.Z);
                    if(Tile==Target) Console.WriteLine("X: "+hRat+" "+vRat);
                    m_Tiles[x+y*m_Width] = new Tile(NewCtr, new Vector2(5.0f, 5.0f)); //Vector3 for position, vector2 for size, which for now is just 5x5 tiles.
                    if(Tile==Target) Console.WriteLine("X: "+m_Tiles[Target].m_Position.X+" "+m_Tiles[Target].m_Position.Y+" "+m_Tiles[Target].m_Position.Z);
                }
            }

 

This is my current result:

 

23gzcld.png

 

if you zoom into the tile(top middle), you can see that it's not exactly center, I think it's more dumb-luck that it looks so close.


Edited by slicer4ever, 13 March 2013 - 07:54 PM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#6 slicer4ever   Crossbones+   -  Reputation: 3901

Like
0Likes
Like

Posted 14 March 2013 - 07:28 PM

so, i decided to hack around this using Project/UnProject, and modifying the screen's depth position, then mapping back.

 

I'm fairly certain this should be possible without having to go through the project/unproject process, but it's just beyond me on how to achieve it.


Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS