PDA

View Full Version : Rotating object by a vector



06-28-2006, 04:27 PM
Hi,

the objects to render are cylinders from (-1,0,0) to (1,0,0) and have a position pos and a direction dir. To render each object I call

foreach object o
{
glPushMatrix
glTranslate(pos)
glRotate(?)
draw cylinder from (-1,0,0) to (1,0,0)
glPopMatrix
}

What are the glRotate calls? I can't find out how to get some angles and axis out of the dir vector.

Thanks

glAren
06-29-2006, 01:17 AM
glRotate (angle, x, y, z) expects angle and rotation vector given by x, y, z and it mutliplies the current transformation matrix by this rotation. If you want to rotate e.g. 50 degrees around y axis, you will call glRotatef (50, 0, 1, 0);

06-29-2006, 06:03 AM
Yes, but I just have the direction vector dir and need an angle and rotation axis for glRotate. Is this the angle between (1,0,0) and dir and the rotation vector the crossproduct of (1,0,0) and dir?

Rob The Bloke
06-29-2006, 06:11 AM
Originally posted by <.:guest:.>:
Yes, but I just have the direction vector dir and need an angle and rotation axis for glRotate. Is this the angle between (1,0,0) and dir and the rotation vector the crossproduct of (1,0,0) and dir? yes