2D to 3D position
I am a beginner in 3D and XNA and can't get my head around 2D to 3D conversion.
I need to convert a mouse X,Y position to a position in my world view at Z=0.
I tried to use Viewport.Unproject twice:
Vector3 near = new Vector3(_2D_point.X, _2D_point.Y, 0);
Vector3 far = new Vector3(_2D_point.X, _2D_point.Y, 1);
near=GraphicsDevice.Viewport.Unproject(near, projectionMatrix, viewMatrix,effect.World );
far=GraphicsDevice.Viewport.Unproject(far, projectionMatrix, viewMatrix, effect.World);
Given that I get 2 Vector points from this, how to I calculate the Vector3 position at Z=0 ???
THANKS
You will get two vectors, one with Z at the near plane and one with Z at the far plane.
These two vectors uniquely determines an infinite line, which you can intersect against the Z=0 plane.
These two vectors uniquely determines an infinite line, which you can intersect against the Z=0 plane.
Edit: Nevermind, I just realized you only need the position on a certain plane. Zao has posted the right approach.
I agree with Zao.
If there is something that feels wrong, check the value of the "effect.World" matrix. You didn't talk about any object so I think it should be identity.
If there is something that feels wrong, check the value of the "effect.World" matrix. You didn't talk about any object so I think it should be identity.
Hi Zao,
>These two vectors uniquely determines an infinite line, which you can intersect against the Z=0 plane.
Thanks! It may be simple, but how do I calculate that intersection point with Z=0?
near: X=-7.82 Y=0.5307 z=-4.4464
far: X=4996.03857 Y=2655.054 Z=1237.23633
What formula do i use to get the intersection with Z=0 ?
Johannes
>These two vectors uniquely determines an infinite line, which you can intersect against the Z=0 plane.
Thanks! It may be simple, but how do I calculate that intersection point with Z=0?
near: X=-7.82 Y=0.5307 z=-4.4464
far: X=4996.03857 Y=2655.054 Z=1237.23633
What formula do i use to get the intersection with Z=0 ?
Johannes
Hi JohannesH,
you need a Ray-Plane intersection test.
This is a good description
http://www.siggraph.org/education/materials/HyperGraph/raytrace/rayplane_intersection.htm
you need a Ray-Plane intersection test.
This is a good description
http://www.siggraph.org/education/materials/HyperGraph/raytrace/rayplane_intersection.htm
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement