Advertisement

Rotation problem

Started by December 20, 2002 09:54 PM
1 comment, last by IVI4j 21 years, 10 months ago
Hello. I''m trying to write a game where some of the rotation done is for spacecraft. At first I thought just tying the input directly to the rotation would do the trick. An example... glRotatef(zAngle, 0.0f, 0.0f, 1.0f); glRotatef(yAngle, 0.0f, 1.0f, 0.0f); glRotatef(xAngle, 1.0f, 0.0f, 0.0f); DrawShip(Raptor, 1); But this didn''t handle even remotely like a real aircraft. So I fiddled with it for a while and got the rotational order X, Y, Z. This corrected the problem with the spacecraft''s roll only. The user''s inputs (+5 to yAngle and -5 to yAngle) made the ship roll. Changing X simply angles the ship up or down no matter what Y is. Any suggestions are appreciated.
Give a man fire and hes warm for a day. Light a man on fire and hes warm for the rest of his life.
It''s gimbal lock, you can''t put those in any order to make it work. You need to use matricies or quaternions.
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
Advertisement
Your problem is that your angles around y and z will be relative to the angle around x, and your z angle will be relative to your y angle (by doing glRotate the first time, you moved your other axis around too, making your other angles false)

You have two options:
a) as one angle changes, modify the two others accordingly
b) define yourself a set of three axis (vRightHandSide, vTop and vFront) which will be oriented as the model is oriented and your three angles will always represent the rotation around these three axis.

Oh yeah, you''ll have to use the formula for rotating a vertex around a random vector (normal):

//rotate angle degrees about a normal
const CVector Rotate(const float angle, CVector& normal) const
{
if(normal.length() != 1) normal.Normalize();
float c=cosfDeg(angle);
float s=sinfDeg(angle);
float t=1-c;

CVector vResult;

float X=normal.x;
float Y=normal.y;
float Z=normal.z;

vResult.x = x*(t*X*X+c) + y*(t*X*Y-s*Z) + z*(t*X*Z+s*Y);
vResult.y = x*(t*X*Y+s*Z) + y*(t*Y*Y+c) + z*(t*Y*Z-s*X);
vResult.z = x*(t*X*Z-s*Y) + y*(t*Y*Z+s*X) + z*(t*Z*Z+c);
return vResult;
}

p.s.: don''t forget to make sure your vector (normal) is normalized (length of 1)


This topic is closed to new replies.

Advertisement