Rotate an off-centred position to always be centred

turbine

New member
Joined
May 27, 2014
Messages
3
Hi,
As this may be a little complicated to explain through words - I'll use images to help.

I've made a minimap which changes the draw point to give the effect of moving around. I can rotate this object if my position is centred to the draw position, however if I'm my position is off from the centred draw position - rotating will change the position showing.

sbrlmwtw.b2u.png
bsrcyzkp.nax.png

n5cl1je1.zkx.png
3lnegmzy.ghb.png


I've been stuck on this for a long time, I can't quite wrap my head around the maths required. Feel free to ask for any info, I'm quite stuck.

Thank you. :)
 
I've made a minimap which changes the draw point to give the effect of moving around. I can rotate this object if my position is centred to the draw position, however if I'm my position is off from the centred draw position - rotating will change the position showing.

I've been stuck on this for a long time, I can't quite wrap my head around the maths required.
What, exactly, are you trying to accomplish? For what, precisely, are you needing maths?

Please be complete. Thank you! ;)
 
What, exactly, are you trying to accomplish? For what, precisely, are you needing maths?

Please be complete. Thank you! ;)
So I need to rotate a square map around another point. Using the x and y coordinate for the map centre position, offsetted by the x and y for the players position (which needs to be centred). When I rotate, the offsetted position doesn't match up.

correct_rotate_grid.png
 
Not sure if this is any help, but it seems your centre of rotation is constantly stuck on the draw position; the green crosshair has rotated 90 degrees about that centre of rotation. If you could somehow make the centre of rotation follow your actual position, I think that would help.
 
Are you familiar with trigonometry? Matrix arithmetic? I'm thinking of the following reply, in another recent thread about rotation.

To rotate (x, y) through angle \(\displaystyle \theta\) about the origin, do the matrix multiplication \(\displaystyle \begin{bmatrix}cos(\theta) & -sin(\theta) \\ sin(\theta) & cos(\theta)\end{bmatrix}\begin{bmatrix}x \\ y \end{bmatrix}\).

To rotate (x, y) through angle \(\displaystyle \theta\) about a point (a, b) that is not the origin
1) translate (a, b) to the origin using (x, y)-> (x- a, y- b)
2) do the matrix multiplication above to get the new (x, y)
3( translate back using (x, y)-> (x+ a, y+ b).

You can read more about this, from a Google search:

https://www.google.com/search?q=rotate+around+a+point+not+the+origin
 
Cheers, that worked.

So programmatically I worked out the offset of the position to the centre of the map. Then I used this with atan2 to get the angle from the centre to my relative position, then I used the angle and the distance to rotate the centre of the map to the correct position.

:) Thank you.
 
Top