Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ahbonk

DirectX 9 Screen to Object Space

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

I have this application where I have a mouse and when I click, I want to know the intersection point of where the mouse is pointing and a plane in which (y = 0, more like a plane on the ground). So I typed in the following script: Public Sub Move(ByVal x As Single, ByVal y As Single, ByVal XD3DDev As Device) Dim vNear As Vector3 Dim vFar As Vector3 Dim Norm As Vector3 Dim RayDir As Vector3 Dim Closest As IntersectInformation Dim t As Single Dim IntersectPoint As Vector3 vNear = New Vector3(x, y, 0) vNear.Unproject(XD3DDev.Viewport, XD3DDev.Transform.Projection, XD3DDev.Transform.View, XD3DDev.Transform.World) vFar = New Vector3(x, y, 1) vFar.Unproject(XD3DDev.Viewport, XD3DDev.Transform.Projection, XD3DDev.Transform.View, XD3DDev.Transform.World) vFar.Subtract(vNear) Norm = New Vector3(0, 1, 0) t = (0 - Vector3.Dot(Norm, vNear)) / (Vector3.Dot(Norm, vFar)) IntersectPoint = Vector3.Add(vNear, Vector3.Multiply(vFar, t)) posX = IntersectPoint.X posZ = IntersectPoint.Z End Sub The problem is, vNear always comes out with two different values, although I have clicked at the same place. Thus, the resuling posX and posZ is always changing although the mouse cursor is at the same place. What do I do? BoNKing the nation!

Share this post


Link to post
Share on other sites
Advertisement

  • 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!