That is a good question... and I will try to answer how I am doing it but keep in mind I am following a tutorial and am interpreting and trying to understand code that wasn't originally written by me.

So the original code was working with a single polygon object, I took the code that made that object "work" and turned it into a C++ class so I can make any number of these objects and make them "work" the same way. Basically every object has an (x,y,z) coordinate, a (dx,dy,dz) velocity vector (dx as in "change in x"), an (xrot, yrot, zrot) rotation angle.

When I press the up arrow key, for example, I simply add a constant value to the current objects dz value (forward/backward is on the z-axis, left-right on the x-axis, and up-down on the y-axis). Every iteration of the main loop I add the dx, dy, and dz values to the x, y, and z coordinates (respectively) for each object. I also (currently, which is the problem) add to the rotation angle in this manner: z-coordinate change = rotate about x-axis, x-coordinate change = rotate about z-axis (and I don't really worry about movement on the y-axis, yet).

So, now I have all these values representing position and rotation but here is how they are applied to the object that is rendered. The first thing I do is load the identity matrix, I then apply rotation and translation for the camera position and vector, then loop through each object doing the following for each: push the current matrix to "save it", translate the matrix based on the current (x,y,z) coordinate of the object, rotate the matrix based on the current angle of rotation of the object, draw the object, then pop the matrix to restore the one that was saved (identity matrix plus camera translation and rotation).

Here are some code snippets to help you follow

Code:

void DrawScene()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
//Rotate and Translate Camera
glRotatef(lookz, 1.0, 0, 0);
glRotatef((360 - lookxy), 0, 1.0 ,0);
glTranslatef(0 - cameraPosition.x, 0 - cameraPosition.y, 0 - cameraPosition.z);
//Draw All Objects
for(unsigned int i = 0; i < cubes.size(); i++)
{
cubes[i]->draw();
}
for(unsigned int i = 0; i < spheres.size(); i++)
{
spheres[i]->draw();
}
}
void sphere::draw()
{
glPushMatrix();
if(active)
{
move();
rotate();
}
glTranslatef(xpos,ypos,zpos);
glRotatef(xrot, 1, 0, 0);
glRotatef(yrot, 0, 1, 0);
glRotatef(zrot, 0, 0, 1);
glBindTexture(GL_TEXTURE_2D, textureIndex);
gluSphere(quadric, radius, 40, 40);
glPopMatrix();
}