Jump to content

  • Log In with Google      Sign In   
  • Create Account

Best way to implement zooming...?


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
3 replies to this topic

#1   Members   

4371
Like
0Likes
Like

Posted 14 June 2013 - 01:11 PM

I pass matrices to my renderables, which they then modify to position themselves correctly according to their position.

 

To my TerrainView class,i also pass my camera matrix.

 

Now, since the terrainview needs to know how much of it is visible (to show the right amount of terrain), it has a separate "zoom" variable (2=2x magnification and so on)

 

However, i feel this doesnt make sense for lets say my sprites (i dont want a zoom value for each sprite ._.)

 

Although my game is 2D orthographic, i still use 4*4 matrices for the camera and rendering. So, to solve my above problem and not have each renderable have their own zoom value, i decided to utilize the Z component of the position of the camera matrix. In my renderables, i get my zoom value by doing 1/camMatrix.z (so for 2x magnification, camMatrix.z must be 0.5), which is somewhat logical since the world is zoomed in when the camera goes closer to the xy plane.

 

That is ugly though, because in my renderables i have to extract the Z coordinate of the camera to calculate the zoom and then scale the positioning matrix to zoom.

 

What would be a more elegant solution?

 

I was thinking of using perspective projection, which would give me proper zoom for the objects that dont need to know wether theyre visible or not and how much zoom there is (currently, of course ill need to cull stuff later...) but i dont know how to best extract the level of zoom from the matrix.

 

So, if i have the camera matrix and the projection matrix, i should somehow be able to find out the zoom (where 2=2x magnification). It only needs to work when the camera is looking down the z axis, and the objects lie on z=0 on the xy plane.

 

The zoom should be taken from the horizontal width of the screen and the horizontal scaling of the world (height of screen should be ignored)

 

Should i multiply the camera and projection matrix together, and what component(s) of the resulting matrix can i use to get the zoom (or the inverse of zoom)?


o3o


#2   Members   

4371
Like
0Likes
Like

Posted 14 June 2013 - 03:29 PM

I THINK if i extract the w component of the resulting matrixs last row i will get the zoom.

But i will try and make a general solution that works for any distance from the camera.

o3o


#3   GDNet+   

6353
Like
1Likes
Like

Posted 14 June 2013 - 05:45 PM

since it's a 2D Game, you can modify your ortho matrix instead, for example:

Vectro3 CameraPos; //CameraPos.x/y = center of screen, z = zoom value.
float Width = Window.Width*0.5f/CameraPos.z;
float Height= Window.Height*0.5f/CameraPos.z;
Matrix4 Ortho = Matrix4.Ortho(CameraPos.x-Width, CameraPos.x+Width, CameraPos.y-Height, CameraPos.y+Height, 0.0f, 1.0f);
you'll probably want two ortho matrixs, one for the ui, and one for the game.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#4   Members   

4371
Like
0Likes
Like

Posted 15 June 2013 - 01:02 AM

Ill just switch to a perspective projection matrix if i ever want some fancy 3D effects :P

o3o





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.