Sign in to follow this  
PdG

D3DXVec3Project

Recommended Posts

i hope this is not a faq, anyway.. i've used the D3DXVec3Project function to translate the 3D coordinates into 2D viewport coords. D3DXVec3Project(&out,&d3dCoords,&viewPort,pProjection,pView,pWorld); out is the 3d vector with the results of 2d coords, d3dCoords is the 3d coords, and others are the classic matrix. Now, it works, but it has a strange behaviour: it returns me the same coordinates when an object is in front of me, and when it's behind. I've checked the .z coord but it's always equal to 1.0000 (or near), i've hoped that if the object is behind, z was below to 0 (i.e. -1.000, but.. nothing, it's always 1.0) So if i need D3DXVec3Project for drawing a sprite that represent a position of a 3d object (try to think to a HUD), the sprite is visible when i've the object in front (right) but also when it's behind (wrong!) Can you help me?

Share this post


Link to post
Share on other sites
You can always perform a dot-product before trying to transform the position.

Take the vector from the eye to the look-at point (used to construct your view matrix) and dot this against the vector from the eye to the object (in world space). If this is a negative value then the object is behind the camera and you don't even need to bother with projecting onto the screen.

hth
Jack

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