Archived

This topic is now archived and is closed to further replies.

sPriTe

More loopy problems

Recommended Posts

I''ve been looking through the forum about rotating objects, but as far as I can see I am translating before rotating as I''m supposed to. But... my objects are not rotating on their own axis, they seem to be rotating around the previous object in oject array. What I want is an object to rotate but stay fixed in space(x,y,z). The current code is as follows: Sphere::Render() { glColor3f(colR, colG, colB); glTranslatef(-x, -y, -z); angle = (float)((angle + 0.1f)); if(angle >= 360.0f) { angle = 0.0f; } glRotatef((float)angle, axisX, axisY, axisZ); auxSolidSphere(diameter); glTranslatef(x, y, z); } and is called from: void Render() { int i; // do rendering here glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); // set eyeline gluLookAt(eyex, eyey, eyez, centrex, centrey, centrez, upx, upy, upz); // draw axis if(axis_on) { DrawAxisPlane(XY); DrawAxisPlane(XZ); DrawAxisPlane(YZ); } for(i = 1; i <= sphere_index; i++) { sphere_object->Render(); } glFlush(); SwapBuffers(g_HDC); } which is in the message loop. If I take out the rotate function, objects are correctly placed but no rotation. If I put in the rotate function all goes mad! Any assistance would be great. Thanks all ;-)

Share this post


Link to post
Share on other sites
Rotation always takes place around the origin (0,0,0). Therefore, if you translate before you rotate, the objects will rotate around the origin - not around their own axis. You need to rotate each object around its own axis first, then translate so they are in the right locations, then rotate again if you need the whole scene to spin. I think this is what you are trying to do. You can of course use matrices and build up a single one that does all of these tasks.
Hope this helps!

Share this post


Link to post
Share on other sites