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,
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.