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
  • 15,031
  • 23
  • 100
  • 187

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,479
  • 4
  • 20
  • 26