# Need math help setting up projection matrix

This topic is 4820 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## 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 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.

1. 1
Rutin
42
2. 2
3. 3
4. 4
5. 5

• 9
• 27
• 20
• 14
• 14
• ### Forum Statistics

• Total Topics
633387
• Total Posts
3011620
• ### Who's Online (See full list)

There are no registered users currently online

×