   openGL rotation help
  greeting, I'm currently a bit stuck on rotation's and its doing my head in as it should be relatively simply, but essentially i need an object i have to face a known point in space...its up orientation is not important just that it turns to face this point in space. I'm also using vectors, so i dont have any matrices holding and information on the objects current transformation. any help would be awesomecheers   
  So you're looking for a rotation that transforms the look vector from its initial direction (i.e. where it points to when the object is not rotated) to its target direction (i.e. pointing towards the aimed location). If these 2 vectors are distinct, then you can use the cross-product to compute the normal of the plane of rotation and the dot-product to compute the angle between them. Then you have an axis/angle rotation representation which can be converted into any other rotation representation.   ;  okay i just attempted something in code and it didnt work out....okay...so. Your advice makes perfect sense  rotationAxis = CurrentLookVec X DesiredLookVec;float angle = CurrentLookVec X DesiredLookVec/ CurrentLookVec.mag * DesiredLookVec.mag;this give me me the angle and the axis to rotate about...but i'm using glRotatef();how do i get openGL to rotate about an axis i define?EDIT: at the moment this is how im trying to calculate the rotationglPushMatrix( );Fvector look = Wanderer->get_pEntityVelocity( ) - Wanderer->get_pEntityPosition( );float angleX = look.y/sqrtf(((look.y * look.y) + (look.z * look.z)));angleX = acosf(angleX);float angleY = look.x/sqrtf(((look.x * look.x) + (look.z * look.z)));angleY = acosf(angleY);glTranslatef( 0, 0, 0 );glRotatef( RAD_TO_DEG( angleX ),1,0,0 );glRotatef( RAD_TO_DEG( angleY ),0,1,0 );glTranslatef( Wanderer->get_pEntityPosition( ).x, Wanderer->get_pEntityPosition( ).y, Wanderer->get_pEntityPosition( ).z );glColor3f( 0,1,0 );glutSolidCone( 1,2,20,20 );glPopMatrix( ); [Edited by - homojedi on April 23, 2010 6:50:06 AM];  glRotate(angle,axisX,axisY,axisZ);That is how you get to rotate on an arbitrary axis.   ;  so....would i do this?rotationAxis = CurrentLookVec X DesiredLookVec;float angle = CurrentLookVec . DesiredLookVec/ CurrentLookVec.mag * DesiredLookVec.mag;glrotate(angle,rotationAxis.x,rotationAxis .y,rotationAxis.z);   ;Quote:Original post by homojediso....would i do this?rotationAxis = CurrentLookVec X DesiredLookVec;float angle = CurrentLookVec . DesiredLookVec/ CurrentLookVec.mag * DesiredLookVec.mag;glrotate(angle,rotationAxis.x,rotationAxis .y,rotationAxis.z);In principal: Yes. But there are 2 caveats. You may have overseen them or neglected beliberately, I don't know, so I tell you:Let i be the initial look vector and d the desired one.Thena := i x dgives the unnormalized axis of rotation. You can normalize it yourselfa / |a|but when used as glRotate's x, y, z values, OpenGL will normalize the axis anyway.Further, the angle between the both vectors isβ := acos( ( i . d ) / ( |i| * |d| )which has to be converted to degrees, of course, before handed over to glRotate.   