aligning vectors?

Hello,
If I have 2 vectors and I want to align one so that it points in the same direction as the other, what would be the best way to do it.

I read of one method, that finds the rotation axis by taking the cross product of the 2 vectors. Then uses the dot product to find the rotation angle. Then, I imagine, you would need to construct a rotation matrix based on this new axis.
This is where I get messed up. If anyone has a link to a site that explains rotation matrix construction, or could explain it themselves, I would be most happy…
Thanks,

Jeremy

If you know the rotation axis and the angle you want to rotate, you can just use glRotate(angle, rotX, rotY, rotZ) where rotX, rotY, rotZ define the rotation axis.

If you want to know the math involved, the formula for determining the rotation matrix is shown in the back of the Red Book, which you can find online. (Sorry… I don’t have a URL offhand, a quick search for Red Book should find it, though.)

The way you calculate the matrix for rotations about the major axes is pretty straightforward, but about an arbitrary axis it gets a bit more complex. I actually had posted some code here awhile ago that builds a matrix from a call similar to glRotate, so if you really want you can search the forms a bit and find that.

Edit: Found the recent thread about how to calculate the matrix for an arbitrary rotation.
http://www.opengl.org/discussion_boards/ubb/Forum2/HTML/008020.html

[This message has been edited by Deiussum (edited 04-19-2002).]

thanks,

The only problem is that I might need to align the vectors before gl is initialized.

But thanks, I will check in the red book, i can find the link.

I will also check out the thread you mentioned.
Jeremy

[This message has been edited by Jeeeez (edited 04-19-2002).]