Hello, I have looked around and have done my best trying to figure out how to most effectively and correctly use a quaternion for rotation using openGL and I am stuck. Here is a snippet of my code:
trans = fallRigidBody->getCenterOfMassTransform();
[self quatToEuler:trans.getRotation():euler];
rotA[0] = euler.getX();
rotA[1] = euler.getY();
rotA[2] = euler.getZ();
....
glPushMatrix();
glLoadIdentity();
glTranslate(...);
glRotatef(rotA[0],1.0f,0.0f,0.0f);
glRotatef(rotA[1],0.0f,1.0f,0.0f);
glRotatef(rotA[2],0.0f,0.0f,1.0f);
[self drawCube:0.1f:0.1f:0.1f];
glPopMatrix();
//////////////
The quaternion returned by "trans.getRotation()" after translated to euler coordinates, with an impulse torque that I give it initially(in the y-direction), increases the y rotation to 180, and then starts decreasing back to 0. At the same time that it starts decreasing it changes both the x and z rotations from 0 to 360. Now I understand this has to do with the quaternions "scalar value" going from +1 to -1, I am just lost in how to correctly use the quaternion to get the orientation and rotation correctly passed to openGL. Any help, suggestions or anything of that nature would be greatly appreciated. Thank you!
using quaternion for GL rotate
-
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
Re: using quaternion for GL rotate
check degrees/radians, left/right- handed issues..
but why mess with rotations at all?
BWT, is it deprecated OpenGL. Also, all (!) functions you use in your OpenGL code above are deprecated...There is no more fixed function pipeline at all.. But it will work, all current drivers support it..
but why mess with rotations at all?
Code: Select all
btTransform t;
float m[16];
if (body->getMotionState())
body->getMotionState()->getWorldTransform(t);
else
t = body->getWorldTransform();
t.getOpenGLMatrix(m);
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glMultMatrixf(m);
// drawCube
glPopMatrix();
-
- Posts: 168
- Joined: Tue Jan 04, 2011 11:47 pm
Re: using quaternion for GL rotate
This seems awesome, learn from it.mi076 wrote:check degrees/radians, left/right- handed issues..
but why mess with rotations at all?BWT, is it deprecated OpenGL. Also, all (!) functions you use in your OpenGL code above are deprecated...There is no more fixed function pipeline at all.. But it will work, all current drivers support it..Code: Select all
btTransform t; float m[16]; if (body->getMotionState()) body->getMotionState()->getWorldTransform(t); else t = body->getWorldTransform(); t.getOpenGLMatrix(m); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(m); // drawCube glPopMatrix();
-
- Posts: 17
- Joined: Sun Sep 25, 2011 8:13 pm
Re: using quaternion for GL rotate
I got it to work, the method that you described was not working for me so I went a different direction, thank you for your responses!
-
- Posts: 144
- Joined: Fri Aug 01, 2008 6:36 am
- Location: Bonn, Germany
Re: using quaternion for GL rotate
it is very strange.. what didn't work? it is assumed you have applied camera transform before (or just load identity if there is no camera)the method that you described was not working for me