Sign in to follow this  
stabo10

Need math help setting up projection matrix

Recommended Posts

I'm making a sprite based game, and I want a camera that is able to zoom in and out. Camera View Point vector (0, 0, -1) Camera Look at Vector (0, 0, 0) All sprites' Z positions are 0. The camera should zoom in by moving on the positive Z axis. At the -1 location I'd like it to get a perfect 1:1 sprite to screen pixel ratio. I'd also like for an increase of 1 on the camera's Vector.x to shift the sprites exactly one pixel to the left on the screen (given the camera's vector.z is currently -1.) Anyone know how to set up the projection matrix to do this? ...or any functions that could create a bridge between this ideal coordinate input system, and the actual view and projection matrices? ------------------ If that is unreasonable, does anyone know how--if using a standard FOV projection matrix, to set the Camera's -Z value so that you will get a perfect 1:1 sprite to screen pixel ratio? Please help me out!

Share this post


Link to post
Share on other sites
I haven't done much with sprites, so I'm not sure what the standard 'pixel perfect' methods are. I will say that you'll probably want an orthographic rather than perspective projection. You can simply set the bounds of the orthographic frustum to the viewport bounds to get (more or less) exact mapping to the screen. There was a thread recently in the OpenGL forum about what sort of tweaks are required to get exact pixel-perfect alignment; I'm not sure how these translate to D3D.

For zooming, rather than move your camera on the z axis, you'll simply change the ortho frustum parameters to map to a smaller area. Keep in mind however that you'll no longer have unit-to-pixel mapping.

Again, I haven't done this - this is all speculative. Perhaps someone who's written sprite-based games in D3D can give you some better advice.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this