I'm writing a Solar System simulator in OpenGL. So one of the components in the Solar System is the Earth's orbit (simple circle around the sun, created by the gluDisk function).
I was wondering how can I retrieve the normal vector of this disk because I need to use it as a rotation vector for the camera (which needs to follow Earth's spin around the Sun).
This is the code (Java) that creates the orbit, it works well. Using this code, how could I retrieve the normal of this disk? (as the disk is contained in some plane, which is defined by some normal).
gl.glPushMatrix();
// if tilt is 0, align the orbit with the xz plane
gl.glRotated(90d - orbitTilt, 1, 0, 0);
gl.glTranslated(0, 0, 0); // orbit is around the origin
gl.glColor3d(0.5, 0.5, 0.5); // gray
// draw orbit
glu.gluQuadricDrawStyle(quad, GLU.GLU_SILHOUETTE);
glu.gluDisk(quad, 0, position.length(), slices, 1);
gl.glPopMatrix();
Before transformation, the disk is in the xy-plane. This means that the normals point in the z-direction,
(0, 0, 1)
. In fact,gluDisk()
will emit these normal during rendering, and the transformations you specify will be applied to them, so for rendering you don't have to do anything.To calculate the transformed normal yourself, you only need to apply the rotation. The translation is not used for transforming normals.
So we need to apply a rotation of
90 - t
around the x-axis to the vector(0, 0, 1)
. Applying the corresponding rotation matrix gives:Applying a couple of trigonometric identities:
gives:
When you apply the
sin()
andcos()
functions in your code, keep in mind that the angles are specified in radians. So if yourorbitTilt
angle is currently in degrees, the normal would be: