• Advertisement
Sign in to follow this  

How to convert world coords to screen coords?

This topic is 4912 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'm creating a 2D game using quads and was wondering if anyone knew how to convert each quad's world coords into screen coords. Even though it's a 2D game, I'm using D3DXMatrixPerspectiveFovLH as opposed to D3DXMatrixOrthoLH. So basically, all of the quads are just as they'd be in a 3D game, but I'm wanting to convert their world coords to screen coords(with 0,0 in the top left of screen).

Share this post


Link to post
Share on other sites
Advertisement
I believe you just transform them by the world-view matrix.

Share this post


Link to post
Share on other sites
why not use D3DXMatrixOrthoLH? you can get rid of z coordinate and simplify your engine without losing 3D effect.
with ortho,your x,y is meassured as screen pixel. use translation matrix to move your quad across the screen.
If you use D3DXMatrixPerspectiveFovLH,you need to find out magic Z value for different resolution,which quite complicated.
you should use ortho projection if you want to do 2D game. I assume your sprite rotation only surround Z axis as most 2D games did.

Share this post


Link to post
Share on other sites
Check the DX Pick sample, it does exactly that, converts world to screen so you can "click" on objects.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement