# [XNA] 2D camera problem

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

## Recommended Posts

hi there,
in my current XNA project i am using a simple 2d camera made by david amador ( i am giving you google cache as his site is down at the moment). the camera is working fine. what is puzzling me is how i can transform my mouse coordinates on the screen to world coordinates depending on the camera's transformation matrix. my math knowledge is obviously not enough, so i will be grateful for any information on the topic.

the way i am trying to solve the problem is not working, but i will post it here so you can give me guidance:

 public Vector2 ConvertScreenToWorldCoordinates(Vector2 location) { var t = Vector3.Transform(new Vector3(location, 0), get_transformation()); return new Vector2(t.X, t.Y); } // transformation matrix from the camera class public Matrix get_transformation() { _transform = Matrix.CreateTranslation(new Vector3(-_position.X, -_position.Y, 0)) * Matrix.CreateRotationZ(Rotation) * Matrix.CreateScale(new Vector3(Zoom, Zoom, 1)) * Matrix.CreateTranslation(new Vector3(_graphics.Viewport.Width * 0.5f, _graphics.Viewport.Height * 0.5f, 0)); return _transform; }

##### Share on other sites
ok, (i think) i solved this.

the problem was that get_transformation() gives us a matrix that we apply on world coordinates to get screen coordinates! and to do the process in the opposite direction (from screen to world coordinates) i have to take the inverse of the matrix and apply it on the coordinates.

• 48
• 12
• 10
• 10
• 9
• ### Forum Statistics

• Total Topics
631380
• Total Posts
2999673
×