Sign in to follow this  

[.net] vector3.Unproject problem

This topic is 3462 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 there, I keep reading every where that vector3.Unproject unprojects a vector from the screen to world(e.g. mouse coordinates). However, what ever vector i give the function the resulting vector is unchanged and is equal to my camera coordinates :S. My world is 3D but i only use the X and Y coordinates and the camera always looks down perpendicular on the plane so it's kinda like 2D. Is that a part of the problem or am i just using the function wrong? here is my code, i am using C#: Vector3 mousePostion3D = new Vector3(0, 0, 0); mousePostion3D.X = MousePosition.X; mousePostion3D.Y = MousePosition.Y; mousePostion3D.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World); Please help, thanks in advance

Share this post


Link to post
Share on other sites
Hi,

IIRC Unproject returns the unprojected vector, so try


mousePostion3D = mousePostion3D.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World);


Regards,
Andre

Share this post


Link to post
Share on other sites

Like Andre said, check your matrices. If you're working with a pure device, device.Transform.* might be silently returning identity matrices. OTOH, it should actually be throwing InvalidCallExceptions when you try to retrieve values from a pure device, so are you sure these matrices are being set up correctly before you use them?

Share this post


Link to post
Share on other sites
Thanks for your help i have found the problem, it seems that i need to project the vector from 000 to the screen to get a Z value and then change the x and y values and then unproject.

Vector3 mousePostion3D = new Vector3(0, 0, 0);

mousePostion3D.Project(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World);

mousePostion3D.X = MousePosition.X;
mousePostion3D.Y = MousePosition.Y;

mousePostion3D.Unproject(device.Viewport, device.Transform.Projection, device.Transform.View, device.Transform.World);

its all in the Z value.

Share this post


Link to post
Share on other sites

This topic is 3462 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.

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