Viewport.Unproject positions for a RenderTarget2D scene (mouse position to world)

I had a similar problem in my current project (w/ one surface) and simply offsetted the ViewMatrix like this:

ViewMatrix = Matrix.CreateTranslation(new Vector3(offset.X, offset.Y), 0)) *
                Matrix.CreateLookAt(
                    new Vector3(SurfaceCenter, 1), 
                    new Vector3(SurfaceCenter, 0), 
                    Vector3.Up);

Theoretically you could do this with all your surfaces and then simply unproject by using the matrices of the corresponding surfaces. This should always give you the exact positions, no matter on which surface the mouse cursor is.

But it’s great that you solved your problem in a different way :slight_smile:

1 Like