orientation from velocity

This is a discussion on orientation from velocity within the Game Programming forums, part of the General Programming Boards category; I'm working on how to make a missile model point the way it's moving. I define the position with a ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    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?
    Illusion and reality become impartiality and confidence.

  2. #2
    vae victus! skorman00's Avatar
    Join Date
    Nov 2003
    Posts
    594
    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.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Velocity in rotation using 2D vectors???
    By blackCat in forum Game Programming
    Replies: 1
    Last Post: 04-10-2009, 10:16 AM
  2. Velocity vector troubles
    By VirtualAce in forum Game Programming
    Replies: 8
    Last Post: 01-18-2005, 11:40 AM
  3. same sex marriages
    By major_small in forum A Brief History of Cprogramming.com
    Replies: 159
    Last Post: 11-29-2003, 03:38 PM
  4. gravity effecting velocity
    By Josh Kasten in forum Game Programming
    Replies: 4
    Last Post: 02-08-2003, 09:22 AM
  5. why do some source save with z as up orientation
    By Shadow12345 in forum Game Programming
    Replies: 6
    Last Post: 12-09-2002, 05:07 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21