Here is the display code. I just don’t understand why the sphere disappear when rotating the viewing angle.
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
GLfloat eyeX = 5 * cos(degToRad(theta));
GLfloat eyeY = 5 * sin(degToRad(theta));
GLfloat eyeZ = rho;
gluLookAt(eyeX, eyeY, eyeZ, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0);
glPushMatrix();
{
glColor3f(0.0, 0.0, 0.9);
glTranslatef(-1.5, 1.5, 0.0);
glutSolidCube(1.0f);
}
glPopMatrix();
glPushMatrix();
{
glColor3f(0.9, 0.0, 0.9);
glutSolidSphere(1/std::sqrt(2), 20, 20);
}
glPopMatrix();
glutSwapBuffers();
}