1

I am making a 2D game, rendered as 3D.

When clicking on my game, I want it to convert those screen space pixel coordinates into worldspace coordinates, knowing the Z axis point (0) that the point should hit.

How can I do this with a function?

I am using XNA with C#.

Mathias Lykkegaard Lorenzen
  • 14,077
  • 22
  • 91
  • 177

1 Answers1

1

Converting from 2d to 3d is unprojecting. there is a built in method within xna for this:

 Vector3 3dWorldPosition = GraphicsDevice.Viewport.Unproject(2DscreenVector & desired Z comp, viewMatrix, projectionMatrix);
Steve H
  • 5,339
  • 3
  • 18
  • 26