Translating mouse position to world position and back is something I already have working. The problem is when I change the position and dimensions of my scene on my RenderTarget. So the world position that is returned is incorrect for the mouse position, since I can move the rectangle around.
The Orange is the clear screen behind the RenderTarget. So I draw the RenderTarget texture onto a rectangle using spriteBatch, but the game world is in 3D (not spriteBatch). If I have the corners of the rectangle against the edges of the screen, it works fine, but moving them around doesn’t translate well.
Camera view and projection:
View = Matrix.CreateLookAt(cameraPosition, cameraLookAt, Up); Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f), Graphics.GraphicsDevice.Viewport.AspectRatio, 0.05f, 10000.0f);
Vector3 nearSource = new Vector3(mousePos.X, mousePos.Y, 0f); Vector3 farSource = new Vector3(mousePos.X, mousePos.Y, 1f); Vector3 nearPoint = Graphics.GraphicsDevice.Viewport.Unproject(nearSource, Projection, View, Matrix.Identity); Vector3 farPoint = Graphics.GraphicsDevice.Viewport.Unproject(farSource, Projection, View, Matrix.Identity);
SpriteBatch.Draw(Scene.Target, Scene.DestRect, Color.White);
How might I go about translating the mouse position correctly for this?