2d Local coords

Blitz3D Forums/Blitz3D Beginners Area/2d Local coords

Terry B.(Posted 2008) [#1]
Say I have a 2d 21X19 Image, and I have to start a bullet from the coords 4,2. Now thats no problem if the image is not rotated, but how do I figure out where to put the bullet if its like at say 10 degrees rotation?


Charrua(Posted 2008) [#2]
Hi

You have to know wich is the center of rotation, suppose, it's the center of the image (10.5 , 9.5 use real numbers, round at final stage)

then, the coords 4,2 relative to the center: -6.5 , 7.5
that's are OldX = -6.5, OldY = 7.5 after a rotation of "alfa" degrees NewX and NewY (respect to the center) are:

NewX = (OldX*Cos(alfa)) - (OldY*Sin(alfa))
NewY = (OldY*Cos(alfa)) + (OldX*Sin(alfa))

if alfa = 10 degrees then: NewX = -7.70361, NewY = 6.25735
(10 degrees anticlockwise, -10 if you want clockwise!)

I hope, someone has a better way (or easyer) but this should work

(remember to translate the newx and newy from center to the correct point)

Juan


Terry B.(Posted 2008) [#3]
Thanks, that worked perfectly.