Get normal of a gluDisk?

395 views Asked by At

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();
1

There are 1 answers

2
Reto Koradi On BEST ANSWER

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:

[ 1     0           0      ]   [ 0 ]   [     0      ]
[ 0  cos(90-t)  -sin(90-t) ] * [ 0 ] = [ -sin(90-t) ]
[ 0  sin(90-t)   cos(90-t) ]   [ 1 ]   [  cos(90-t) ]

Applying a couple of trigonometric identities:

cos(90 - t) = sin(t)
sin(90 - t) = cos(t)

gives:

[     0      ]   [    0    ]
[ -sin(90-t) ] = [ -cos(t) ]
[  cos(90-t) ]   [  sin(t) ]

When you apply the sin() and cos() functions in your code, keep in mind that the angles are specified in radians. So if your orbitTilt angle is currently in degrees, the normal would be:

xNormal = 0.0;
yNormal = -cos(orbitTilt * (M_PI / 180.0));
zNormal = sin(orbitTilt * (M_PI / 180.0));