Reputation: 11513
I'm working through the OpenGL Superbible ( 4th Edition ). Chapter 4 has an example of rotating electrons about a nucleus. ( basically small spheres about a single larger sphere).
Here is an extract of the render function, which draws an electron ( a sphere) in a particular position about a nucleus (another sphere). fElect1
is an angle that is incremented by 10 degrees on each call to render.
glPushMatrix();
glRotatef(360.0f-45.0f,0.0f, 0.0f, 1.0f);
glRotatef(fElect1, 0.0f, 1.0f, 0.0f);
glTranslatef(0.0f, 0.0f, 60.0f);
glColor3ub(56,136,21);
glutSolidSphere(6.0f, 15, 15);
glPopMatrix()
So - he rotates the view by 315 degrees about the z-axis. And then rotates the view about the newly rotated y-axis by the angle fElect1
and then draws the sphere. i.e. he wants to simulate an orbit of an electron around the y-axis. The result is that the electron appears to move in a 'tilted' orbit about the sphere ( tilted because the x-axis has been tilted by 315 degrees ).
But my question is - why does he translate on the z-axis? wouldn't this mean that the electron has a sort of orbit where the nucleus is not at the centre of it's path? But it doesn't look like that when I run the simulation.
Upvotes: 0
Views: 752
Reputation: 16612
I think perhaps you're thinking of the operations from the wrong direction. They way they are applied in GL, you apply the most 'global' transformation first, and the most 'local' last. So in thinking of how something will be transformed, you may want to think about them in the reverse order.
So:
Upvotes: 1