Jump to content
  • Advertisement
Sign in to follow this  

Getting right mouse position

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



First thanks for every help I get. I am new in DirectX and SlimDx. This is why I first developed a test application. Later I want to develop a 2D game. Now to my Problem. I want to get the mouse position in the 3D space. But I have problems with the calculation of the point.

#region fours try

float m_iClientSizeW = _control.Device.Viewport.Width;
float m_iClientSizeH = _control.Device.Viewport.Height;

Matrix worldview = _control.Device.GetTransform(Dx9.TransformState.View);
Matrix worldviewprojection = Matrix.Multiply(worldview, _control.Device.GetTransform(Dx9.TransformState.Projection));

Dx9.Viewport vp = _control.Device.Viewport;

// Unproject near plane
Vector3 vNear = new Vector3((float)posPoint.X, (float)posPoint.Y, 0);
Vector3 vFar = new Vector3((float)posPoint.X, (float)posPoint.Y, 1);

Vector3 vNearW = Vector3.Unproject(vNear,
            0, 0,
            m_iClientSizeW, m_iClientSizeH,
            0, 1, Matrix.Identity * worldviewprojection);

Vector3 vFarW = Vector3.Unproject(vFar,
            0, 0,
            m_iClientSizeW, m_iClientSizeH,
            0, 1, Matrix.Identity * worldviewprojection);

Ray ray = new Ray(vNearW, vFarW - vNearW);

Here you can find my source code: https://github.com/ascholz/SlimDxTest


I have rode this article, http://www.vb6.us/tutorials/using-mouse-click-3d-space-directx-8 . But I have problems defining the plane for the z equals zero.


I hope someone can help me.


Best Regards



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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!