View Full Version : I neeeeeed HELP with Rotation!!! as soon as posible!!

06-11-2000, 03:50 PM
Let say I have a Spaceship in space.
I also have a asteroid in the same space.
I want a to be able to rotate a camera around the ship.

I want to be able to rotate the ship, here is the big problem. When I rotate around the first axle (Let say X) the whole system rotates so when I later want to rotate around some other axle it have moved and the ship donít rotate as I want.

I rotate 90 degrees around X this moves Y to where Z was and Z to where Y was.
If I now want to rotate around Z the ship will rotate around Y.
And that is NOT what I want! ! !

What I am trying to do is a Ship that:
Turn its Nose UP or Down (its own X) when key pressed, however it is turned in any way.
Rotates around its own Z when LEFT/RIGHT key is pressed

06-14-2000, 06:01 AM
You can find these formulas pretty quickly anywhere on the web .. or in a decent book on 3D.

It seems like you already have these (from my code):
const double sx = sin(xAngle), cx = cos(xAngle);
const double sy = sin(yAngle), cy = cos(yAngle);
const double sz = sin(zAngle), cz = cos(zAngle);

xtemp = points[i].X;
ytemp = points[i].Y;
ztemp = points[i].Z;

points[i].X = xtemp;
points[i].Y = (ytemp * cx) - (ztemp * sx);
points[i].Z = (ytemp * sx) + (ztemp * cx);

points[i].X = (xtemp * cy) + (ztemp * sx);
points[i].Y = ytemp;
points[i].Z = (ztemp * cy) - (xtemp * sy);

points[i].X = (xtemp * cz) - (ytemp * sz);
points[i].Y = (xtemp * sz) + (ytemp * cz);
points[i].Z = ztemp;

If you want to rotate around a local point (instead of axis) the easiest way is probably to translate the point(s) in respect to 0,0,0 and then back. Example if you want to rotate about 0,5,0 shift all the y-values by -5, rotate, and then shift all the y-values by +5 again. I know there are eqn's to rotate around a point in space instead of 0,0,0 but don't have my references here.