gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Rotating around a point

#17689 - Lupin - Fri Mar 12, 2004 5:33 pm

I am currently working on a voxel renderer and i have a mathematical problem. My airplane is right in front of my view, so if i rotate my plane i don't want to rotate around the cameras position but around the actual plane! What i am doing now is just rotating around my camera position.

How can i rotate my camera position around my plane? The problem i got is that i also have a angle of the camera that got to be changed too (but i think i just got to subtract the amount of rotation for it).

Well, i hope you understood my question :)

A explanation on how to rotate a point around another point in 2D space would help a lot too!

#17691 - shadow_gg - Fri Mar 12, 2004 6:12 pm

hello,that's strange u can do a voxel but u don't know how to rotate points!
so simple!
the formulaes for rotating around a point are:
(that comes from GBATEK and it is good)

Calculating Rotation/Scaling Parameters A-D
A = Cos (alpha) / xMag ;distance moved in direction x, same line
B = Sin (alpha) / xMag ;distance moved in direction x, next line
C = Sin (alpha) / yMag ;distance moved in direction y, same line
D = Cos (alpha) / yMag ;distance moved in direction y, next line



Calculating the position of a rotated/scaled dot
Using the following expressions,
x0,y0 Rotation Center
x1,y1 Old Position of a pixel (before rotation/scaling)
x2,y2 New position of above pixel (after rotation scaling)
A,B,C,D Parameters (as calculated above)


the following formula can be used to calculate x2,y2:
x2 = A(x1-x0) + B(y1-y0) + x0
y2 = C(x1-x0) + D(y1-y0) + y0


for the rotation of ur camera, just add the angle of rotation to ur camera angle!
I hope it will help u
good luck!

#17728 - Lupin - Sat Mar 13, 2004 2:07 pm

Thank you!

#17729 - Lupin - Sat Mar 13, 2004 2:27 pm

It doesn't work... I tried to test it using windows, but it didn't work..

I found out that it should be:
xnew=(xold-x0)*cos(phi)+(yold-y0)*sin(phi)+x0
ynew=-(xold-x0)*sin(phi)+(yold-y0)*cos(phi)+y0