Original Post
I want to convert a 3d position to a 2d screen coordinate. But i'm not really sure how to do that.
I know i need the view, projection and world matrix for the calculations. So i managed to get those. But what next? How can i calculate the 3d position of an object to a 2d screen position?
This is how i get the matrices:
I know i need the view, projection and world matrix for the calculations. So i managed to get those. But what next? How can i calculate the 3d position of an object to a 2d screen position?
This is how i get the matrices:
[size="2"]D3DXVECTOR3 vector_2d, vector_3d(0,0,0);
[size="2"]D3DXMATRIX view_matrix, proj_matrix, world_matrix;
[size="2"]D3DVIEWPORT9 d3dvp;
[size="2"]dev->GetTransform( D3DTS_VIEW, &view_matrix );
[size="2"]dev->GetTransform( D3DTS_PROJECTION, &proj_matrix );
[size="2"]dev->GetTransform( D3DTS_WORLD, &world_matrix );
[size="2"]dev->GetViewport( &d3dvp );
[size="2"]D3DXVec3Project( &vector_2d, &vector_3d, &d3dvp, &proj_matrix, &view_matrix, &world_matrix );
[size="2"]D3DXVec3Unproject( &vector_3d, &vector_2d, &d3dvp, &proj_matrix, &view_matrix, &world_matrix );
[size="2"]