Get model to face direction of movement - SOLVED

This is a question that has been asked in MANY forums on the web as I've been reading most of them :s

That said, I'm still confused as to how to orient my 3D model to face the direction of travel. I have a normalized 3D vector that is pointing in the direction of travel and I want to orient my model to face that direction.

I'm thinking I need to create a 3D matrix from that vector, but all the examples I've been trying cause the model to rotate in all sorts of ways, but never face the direction I expect.

At the moment I'm trying to create a matrix from a vector using code that was inside the gluLookAt function. This code looks like this:

This is what gluLookAt does -- given a forward vector and an up vector:

normalize both
cross forward and up to get right/left (depending on handedness and order of cross product)
cross forward and right/left to get new up
use forward, right/left and new up as a rotation matrix

Of course, there are two cross products that you can change the order of to get the wrong answer, several stages that may or may not need renormalization, and you'll have to fight the fact that OpenGL's matrices aren't the same way round as your linear algebra text.

Your code would be a lot easier to read if you defined some functions like "normalize" and "cross".

If you're having difficulty doing this via gluLookAt, or your own UVN rotation code isn't working, you could also just go brute-force on it and use some trig, as long as you aren't using it for anything particularly performance critical. This is assuming up is toward the zenith, so roll isn't taken into account here. I don't know if this code works or not. I just butchered it together for some ideas of how to approach it brute-force style. I put in two functions, one for y being the zenith and one for z being the zenith.

Code:

enum
{
RHO, // distance from origin to point
THETA, // similar to longitude (azimuth)
PHI // similar to latitude (altitude, elevation, or inclination)
};

You'd use it, something like this, where myPoint would be your movement vector and mySphereCoords would be filled in with angles you can use to rotate your object with to match the direction vector (theoretically anyway, like I said, I don't know if this works or not ):

Thanks for the help guys. Based on your info and so more reading I've created a function that will create a matrix that can be used to orientate my model in the direction they are travelling, or any direction I pass in.