# 2d tile map render rotation math?

I am working on a personal project and am trying to make a 2d tile map render that needs to handle rotation.

I am using raylib to handle the drawing stuff onto the screen and am using this function to draw a tile:

void DrawTexturePro(Texture2D texture, Rectangle sourceRec, Rectangle destRec, Vector2 origin, float rotation, Color tint);


How do I calculate the new coordinates of the tiles after the rotation and the individual rotation of each tile if I want to rotate the tile map?

I also need to figure how to do mouse click detection for tiles when they are rotated with their new coordinates and how to do ‘collision detection with cursor’ with rotated squares/tiles.

And due to the way the project is set up I cannot rotate the camera.

Extra info/diagram:

• When you say you have no means to rotate the camera, do you mean the entire rendering code from that point onwards is out of your control? Or do you have any way to alter the model-view-projection matrices for calculating the vertex positions? – user111144 Jan 3 '18 at 14:47
• No I need other items being rendered to not turn with the grid so I do not want to alter the camera. – Mclog21 Jan 4 '18 at 2:23

You will need to transform the point by a rotation/transformation matrix.

Wikipedia has good information about using rotation matricies https://en.wikipedia.org/wiki/Rotation_matrix

X,Y are your coordinates of your object (represented as a column vector/1D matrix)
X',Y' are your new, rotated coordinates

[X'] = [cosθ -sinθ][X]
[Y'] = [sinθ  cosθ][Y]


This is a small amount of matrix math equating to

X' = [cosθ * X] + [-sinθ * Y]
Y' = [sinθ * X] + [ cosθ * Y]


You can use transformation matrices for lots of operations such as translations, scaling, rotation, skewing, etc. They are widely used in 3D graphics

get rotation flag from tile,parse it and swap coordinates from your vertexes

Here good engine and good example where you can find how to do it

https://github.com/oxygine/oxygine-framework/commit/3d02d81e0b3851bab705aaea72d5a0375c9ea432

• Please elaborate as to why you suggest this is a solution to the problem, and properly format your answer. – Stephan Jan 3 '18 at 14:25
• I add example about what i mean – Yahor10 Jan 3 '18 at 14:59
• Adding a link to an external site is not the way to go, as links die. This answer is not very useful in its current state. – Tyyppi_77 Jan 3 '18 at 21:59
• How links can die for official documentation ? – Yahor10 Jan 4 '18 at 15:34
• that library may not exist forever. It's also not specific to his problem – CobaltHex Jan 5 '18 at 1:24