Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

CoderX

Best matrix for Projection -> 2D

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have been trying to find the best projection matrix. So far D3DXMatrixPerspectiveFovLH seems to be the best. When I rotate my sprites, the above matrix works fine, but the sprite rotates funny when I use D3DXMatrixOrthoLH. It kinda stretches and shrinks. It might also have to do with the aspect ratio, since putting it at SCREEN_WIDTH/SCREEN_HEIGHT seems to fix the rotation problem for the D3DXMatrixPerspectiveFovLH matrix. So I just want to know whats the best matrix to use for Projection space. Thanks.

Share this post


Link to post
Share on other sites
Advertisement
If you want to do true 2d, that is, never use the z-coordinate, Ortho is best. However if you do want to change the z coordinate perspective is best. Remember that when using ortho you are using SCREEN coordinates. 0 to screenwidth and height. Where in perspective you use the actual WORLD coordinate. That is units from approx -4,5 to +4,5 if the view looks at 0,0,0 in 800x600 resolution.

Share this post


Link to post
Share on other sites
Okay, thanks for the reply and its a good answer.

Now the reason I use z-axis for 2d is that I read on a tutorial that its easier to calculate how to draw the objects in order. So instead of drawing the objects in order of distance from camera (farthest first, nearest last), I could just assign different z-values and then draw in any order.

So I guess using the perspective is the best way. Thanks again.

Share this post


Link to post
Share on other sites
Okay, now I ran into another problem, and after searching thru previous posts (too many to remember), I learned a lot but not enough.

Anyway, here is my PROJECTION matrix setup:
D3DXMatrixPerspectiveFovLH(&mat, D3DX_PI/4, (float)pWindow->iWidth/pWindow->iHeight, 1.0f, 100.0f);

I know what all the parameters do. I want to use this matrix instead of the regular Perspective is because I want the camera-zoom effect. I would have to play around with the FOV (2nd argument).

Now I am doing a 2d game. I want to be able to find out the edges of the screen and use it for clipping and whatever else. The problem is that I can''t seem to find the exact edges of the screen.

I know that the sdk has formulas to calculate it, but after some number-crunching, the values I get are much bigger than the screen width and height (yes, I divided by 2 since it starts at 0,0,0).

So basically, I just want to know the screen width and height using this matrix for Projection view. Thanks

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!