Sign in to follow this  
CastorX

Mouse pointer in 3D space

Recommended Posts

CastorX    132
Hy! Is there a helper function in XNA that helps to convert the mouse pointer position from screen-space to 3D space, and maybe returns a ray pointing from the viewer's screen plane to the corresponding direction of the far clip plane? The method I used until now extracts the 6 planes from the view*projection matrix, determines the intersection points of the frustum planes and then interpolates between them using the position of the mouse pointer on the screen. I'was just wondering if there is a simpler method to do this in XNA (or D3D9,10,11). Thanks!

Share this post


Link to post
Share on other sites
arriu    100
Quote:
Original post by CastorX
Hy!
Is there a helper function in XNA that helps to convert the mouse pointer position from screen-space to 3D space, and maybe returns a ray pointing from the viewer's screen plane to the corresponding direction of the far clip plane?


Yes, you can use GraphicsDevice.Viewport.Unproject()
Here is a guide on how to use it: http://msdn.microsoft.com/en-us/library/bb203905.aspx

Also, a quick google for "xna picking" will give you more results and sample code. Hope that helps =)

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