I am writing a graphics program in C++ utilizing openGL. It is the typical "solar system" exercise where I have a central object (the sun) rotating on its axis and 2 planets orbiting the sun rotating on their axis'. The viewer (camera) is on a satellite that is in the outermost orbit of the solar system so that all objects are visible at the same time. The satellite can move either direction in its orbit. (orbit to the right, orbit to the left). The satellite can rotate on its own axis while always facing the sun. In other words the "up" direction can change simultaneously while orbiting the sun. How do I calculate the vector for the "UP" position given an angle of rotation and the current x, y coordinates. Specifically, how do I calculate the z coordinate with respect to x, y, theta? ("up" is defined as the reference vector in which you perceive "up" to be. If I tilt my head 45 degrees to the right, up for me would be the vector (1, 1))

For Example:

Satelite is located at (0, 0, 1) facing the origin. The normal up vector would be (0, 1, 0)(WRT the origin translated to the satellite) or (cos(theta)*r, sin(theta)*r, 0.0). If I rotate the "up" position by 45 degrees (rotate the satellite axis by 45 degrees) this formula works fine as long as I'm stationary at location (0, 0, 1). If I move the satellite to position (cos(60), 0.0, sin(60)) in the satellite orbit and I want to rotate the satellite on its axis by 45 degrees (while always facing the origin), the z coordinate changes also. How do I calculate the (x, y, z) coordinates for my up position as I orbit about the origin on the plane x = 0??

For Example:

Satelite is located at (0, 0, 1) facing the origin. The normal up vector would be (0, 1, 0)(WRT the origin translated to the satellite) or (cos(theta)*r, sin(theta)*r, 0.0). If I rotate the "up" position by 45 degrees (rotate the satellite axis by 45 degrees) this formula works fine as long as I'm stationary at location (0, 0, 1). If I move the satellite to position (cos(60), 0.0, sin(60)) in the satellite orbit and I want to rotate the satellite on its axis by 45 degrees (while always facing the origin), the z coordinate changes also. How do I calculate the (x, y, z) coordinates for my up position as I orbit about the origin on the plane x = 0??

What you really want to do is change the order of translation/rotation.

glPushMatrix();

position();

glPushMatrix();

glRotatef(rotate, 0.0f, 1.0f, 0.0f);

glPopMatrix();

glRotatef(45.0f, 0.0f, 0.0f, 1.0f);

drawmodel();

glPopMatrix();