Alphapage
Alphapage

Reputation: 919

Translate coordinates to another plane

My main plane is Rectangle(0,0,10000,10000) for example.

My screen plane (ie virtual position) is Rectangle(1000,1000,1920,1080).

My Texture2D is Rectangle(1500,1200,200,100) in main plane.

I need to translate my Texture2D coordinates to my screen plane. I tried with Matrix.Translate without success. I must get Texture2D = Rectangle(500,200,200,100) in screen plane.

Upvotes: 0

Views: 173

Answers (1)

RdeGier
RdeGier

Reputation: 26

In order to get the Texture2D from (1500, 1200) to (500, 200) you have to use a translation of (-1000, -1000) which are the inverse numbers from your screen plane's coordinates. In code your translation would be something like this

Matrix transform = Matrix.CreateTranslation(-screenPlane.x, -screenPlane.y, 0);

The theory is that you want to move the texture like if your camera was on (0, 0) instead of (1000, 1000). You have to move the texture by (-1000, -1000) in order to do so.

Check the web for 2D camera classes, always usefull to know how cameras work :) This one for example: http://www.david-amador.com/2009/10/xna-camera-2d-with-zoom-and-rotation/

Upvotes: 1

Related Questions