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)?