Jump to content
  • Advertisement
Sign in to follow this  
JohannesH

Viewport.project unproject question

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

Using XNA 3.1, I am trying to get world x,y coordinates back from a mouse click. I am trying to find the world x,y position at z=0, however I can't seem to figure out how. I unproject twice in the sample below. AT first with z=0, then with z=1. Since my mouse test data is 10,10 and my world 0,0,0 is at about 200,200 pixels, I would have expected x,y coordinates to be very different than what I get. :-( How do I get my x,y world coordinates from my Mouse X,Y assuming z at 0 ??? result from code below: MouseY,MouseY=10,10 -> -7.763712 ,-0.5084655 ,-4.569074 MouseY,MouseY 2=10,10 -> 5322.184 ,-2543.376 ,623.7775 Pixel=9.999941 ,10 ,-5.522809E-07 This is the code I am using: int MouseX = 10; int MouseY=10; Vector3 pos = new Vector3(); pos = GraphicsDevice.Viewport.Unproject(new Vector3(MouseX, MouseY, 0), effect.Projection, effect.View, effect.World); System.Diagnostics.Debug.WriteLine("MouseY,MouseY=" + MouseX + "," + MouseY + " -> " + pos.X + " ," + pos.Y + " ," + pos.Z); Vector3 pos2 = new Vector3(); pos2 = GraphicsDevice.Viewport.Unproject(new Vector3(MouseX, MouseY, 1), effect.Projection, effect.View, effect.World); System.Diagnostics.Debug.WriteLine("MouseY,MouseY 2=" + MouseX + "," + MouseY + " -> " + pos2.X + " ," + pos2.Y + " ," + pos2.Z); pos = GraphicsDevice.Viewport.Project(new Vector3(pos.X, pos.Y, pos.Z ), effect.Projection, effect.View, effect.World); System.Diagnostics.Debug.WriteLine("Pixel=" + pos.X + " ," + pos.Y + " ," + pos.Z);

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!