orientation from velocity
I'm working on how to make a missile model point the way it's moving. I define the position with a vector and the velocity as a normalized vector that I scale for speed and time. The method that I use to extract the velocity is:
Code:
Missile(float _speed, float _yaw, float _pitch, Vec _pos) {
name = "Missile";
speed = _speed;
pos = _pos;
yaw = _yaw;
pitch = _pitch;
vel.set(cosf(yaw),sinf(pitch),sinf(yaw));
vel.normalize();
totalTime = 10.0f;
modelName = "missile.ms3d";
}
The line that moves the missile, which works correctly, is:
Code:
pos += vel * (dtimef * speed);
Since this works, I know that the velocity vector is at least pointing in the right direction. The problem comes up when I try to render the missile:
Code:
glPushMatrix();
glTranslatef(pos.x,pos.y,pos.z);
glRotatef(yaw*58.6319f,0.0f,1.0f,0.0f);
glRotatef(pitch*58.6319f,1.0f,0.0f,0.0f);
//render the model
glPopMatrix();
The 58.6319f's are in there to convert yaw and pitch from radians to degrees, so I think that should be working, except the model points in weird directions. What am I doing wrong?