Originally Posted by
Bubba
This makes no sense since it is impossible to rotate an object around it's center only in world space. The rotation is happening in local space about the origin and then the object is being translated to it's world space position. Anything else would result in the object rotating around the point it was translated from (IE: 0,0,0 in local space).
Yes you are right Fortunately I have crossed that stage.
Here is my code structure :
I am reading an obj file, and rendering it, This whole thing is a class. ie for every obj file there is a object, and in every object there is code to render that object separately.
I am calling this render functions from A MAIN RENDER LOOP.
Here is the code snippet for the render code for the INDIVIDUAL OBJECTS.
In Original Render Loop there is a glLoadIdentity();
Code:
// Save the current transformation by pushing it on the stack
glPushMatrix();
//////////////////////////////////////////////// Calculating the screen space orientation
glGetFloatv(GL_MODELVIEW_MATRIX, cameraMat); // Save the current matrix containg the gluLookat data
glPushMatrix();
glLoadIdentity();
if(dRot.x) // Delta Rotation Structure
glRotatef(dRot.x, 1.0f, 0.0f, 0.0f);
if(dRot.y)
glRotatef(dRot.y, 0.0f, 1.0f, 0.0f);
if(dRot.z)
glRotatef(dRot.z, 0.0f, 0.0f, 1.0f);
dRot.x = 0.0f;
dRot.y = 0.0f;
dRot.z = 0.0f;
glMultMatrixf (matrix);
glGetFloatv(GL_MODELVIEW_MATRIX, matrix); // Saving the new matrix
glPopMatrix();
//glLoadIdentity();
// Translate to the current position
glGetFloatv(GL_MODELVIEW_MATRIX, cameraMat);
glTranslatef(pos.x, pos.y, pos.z);
//Rotating the object
glRotatef(rot.x, 1.0f, 0.0f, 0.0f); // In the object space
glRotatef(rot.y, 0.0f, 1.0f, 0.0f);
glRotatef(rot.z, 0.0f, 0.0f, 1.0f);
glMultMatrixf(matrix); // Before first run this is initiaized to unit matrix
// In the world space
// Scaling the current object
glScalef(scale.x, scale.y, scale.z);
/////////////////////////////////////////////////////////////////////////////////////
//vertex array loaded and rendered
Now With this code I am doing free form Rotation,'
At this point I need to snap the object to 90 degree or its multiple in any of the axes.
THANKS FOR YOUR REPLY.