# [DX9] D3DXVec3Unproject

## Recommended Posts

G-Man9566    122
Hi, For a specific implementation, I am projecting an object from Object space (EDIT: maybe this is where I am getting it wrong, since Im not sure if this is the position in World Space or Local/Object Space, which would the just be 0, 0, 0 ) to Screen space using D3DXVec3Project and a perspective projection matrix. I am then projecting the Screen space coordinates back to Object space using D3DXVec3Unproject and an orthographic projection matrix. I am not 100% sure that I am giving the functions the correct parameters. Could someone help me with this....
D3DXVECTOR3 l_d3dvGizmoPositionInScreenSpace( 0.0f, 0.0f, 0.0f );
D3DXVECTOR3 l_d3dvGizmoPositionInOrthoWorldSpace( 0.0f, 0.0f, 0.0f );

D3DXVec3Project( &l_d3dvGizmoPositionInScreenSpace, // Out - Screen Space Position/Coordinates
&m_vGizmoWorldPosition, // Gizmo Position in world space
&GetViewport( D3DVPT_PERSPECTIVE )->m_d3dViewPort, //Viewport rendered in
&l_mPerspectiveProjectionMatrix, // The perspective matrix projected with
&l_mViewMatrix, // the view matrix of the "camera" in the viewport
&m_mGizmoWorldMatrix() ); // the world transformation matrix of the gizmo

D3DXVec3Unproject( &l_d3dvGizmoPositionInOrthoWorldSpace, // Out - World space coordinates
&l_d3dvGizmoPositionInScreenSpace, // Gizmo Position in Screen space
&GetViewport( D3DVPT_PERSPECTIVE )->m_d3dViewPort,//Viewport rendered in
&l_mOrthographicProjectionMatrix(), // The perspective matrix (un)projected with
&l_mViewMatrix, //the view matrix of the "camera" in the viewport
&l_d3dmScreenSpaceMatrix); // And here I am not sure what matrix should be used??



##### Share on other sites
G-Man9566    122
Well, my main fault was that the 2nd parameter of D3DXVec3Project should have been the gizmo's local space position, which is always (0, 0, 0) in my case.

Then the second fault was that the World matrix for D3DXVec3Unproject had to be a Identity matrix.

When I corrected these 2 mistakes it works perfectly!