Jump to content
  • Advertisement
Sign in to follow this  
G-Man9566

[DX9] D3DXVec3Unproject

This topic is 3044 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

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 this post


Link to post
Share on other sites
Advertisement
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!

Share this post


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

  • Advertisement
×

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!