# orientation from velocity

• 08-27-2005
ichijoji
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?
• 08-27-2005
skorman00
Try fiddling around with a negative in a few places; You may be using different points of origin for your rendering and your calculations, and not even realize it. Personally, I would use the components of the velocity vector instead of storing yaw and pitch.
• 08-28-2005
VirtualAce
You need to create a look at matrix. DirectX provides this functionality in the D3DX library - but for OpenGL you can find the source to create a look at matrix on several sites. Google for constructing a look-at matrix in OpenGL or something similar.