PDA

View Full Version : Rotating with user input



OGL_PGR
09-17-2005, 04:07 AM
Please help me with rotation of an object with mouse input :

I have a 'Intermediate' quaternion which goes from 'Initial' quat to 'Final' quat through SLERPing.

Intermediate = QuaternionSLERP(
InitialQuaternion ,
FinalQuaternion ,
ALPHA); // goes from 0.0 to 1.0

// ObjectAxis is a 'Vector',
// ObjectAngle is a 'float'

QuaternionToAxisAngle(
Intermediate,
&ObjectAxis,
&ObjectAngle);

Then, somewhere in DrawGL() loop :
...
...
// RTOD = (180.0/PI)
glPushMatrix();
glRotatef(
ObjectAngle*RTOD,
ObjectAxis.x,
ObjectAxis.y,
ObjectAxis.z);
// draw a sphere
auxWireSphere(40.0f);
glPopMatrix();
...
...
ALPHA+=1.0f;
If(ALPHA>=1.0f)
ALPHA=0.0f;
...

Can someone please let me know as to how I could apply the same 'SLERP' technique for rotating the object via MOUSE input in Win32 ?

Thanks.

Hlz
09-17-2005, 09:37 AM
Try a google for "opengl and trackball".
http://www.codeproject.com/opengl/virtualtrackball.asp

I suggest you build yourself good quaternion and matrix classes, with conversions to and fro. A good foundation like this makes the camera stuff a breeze. Once you have the final composite camera quat, convert it to a matrix and give it to opengl via glLoadMatrixf.

P.S. If you're after a "chase" effect, calculate the desired "to" quat, then slerp a persistent "from" quat over a certain period of time or number of frames.