# 2D to 3D position

This topic is 3017 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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

##### Share on other sites
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.

##### Share on other sites
Edit: Nevermind, I just realized you only need the position on a certain plane. Zao has posted the right approach.

##### Share on other sites
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.

##### Share on other sites
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

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 14
• 12
• 9
• 12
• 37
• ### Forum Statistics

• Total Topics
631434
• Total Posts
3000049
×