Objectives

Setup

Perspective

  //glOrtho (-100.0f, 100.0f, -100.0f, 100.0f, -100.0f, 100.0f);
  gluPerspective(60.0f, 1, 50.0, 400.0);
  glTranslatef(0.0f, 0.0f, -200.0f);

Exercise 1: gluPerspective Parameters

Camera

  glTranslatef(0.0f, 0.0f, -200.0f);
  glutSpecialFunc(specialKeys);
void specialKeys(int key, int x, int y)
{
}
  int left=0, right=0;

  left  = (key == GLUT_KEY_LEFT)?     5 : 0;
  right = (key == GLUT_KEY_RIGHT)?   -5 : 0;
  glTranslatef(left+right, 0.0f, 0.0f);
  glutPostRedisplay();
  int up=0, down=0;
  int left=0, right=0;
  int in=0, out=0;

  up    = (key == GLUT_KEY_UP)?      -5 : 0;
  down  = (key == GLUT_KEY_DOWN)?     5 : 0;
  left  = (key == GLUT_KEY_LEFT)?     5 : 0;
  right = (key == GLUT_KEY_RIGHT)?   -5 : 0;
  in    = (key == 9)?       5 : 0;   // tab
  out   = (key == 32)?      -5 : 0;  // space

  glTranslatef(left+right, up+down, in+out);
  glutPostRedisplay();

Solar System

void renderEarthMoon(int moonAngle)
{
  glPushMatrix();
    Color::Blue.render();
    glutSolidSphere(15, 15, 15);

    Color::Green.render();
    Vector3::UnitY.rotate(moonAngle);
    Vector3(30.0f, 0.0f, 0.0f).translate();
    glutSolidSphere(6.0f, 30, 17);
  glPopMatrix();
}
void renderSolarSystem(void)
{
  static int moonRot = 0;

  glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

  glMatrixMode(GL_MODELVIEW);
  glPushMatrix();
    renderEarthMoon(moonRot);
  glPopMatrix();

  moonRot  = (moonRot + 10) % 360;

  glutSwapBuffers();
}
  glutDisplayFunc(renderSolarSystem);

  //glTranslatef(0.0f, 0.0f, -200.0f);
  //...
    Vector3(100,0,0).translate();
  //...

  //...
    Color::Yellow.render();
    glutSolidSphere(15.0f, 30, 17);
  //...

void renderEarthMoon(int earthAngle, int moonAngle)
{
    Vector3::UnitY.rotate(earthAngle);
  static int earthRot = 0;
  //...
  earthRot = (earthRot + 5) % 360;
    renderEarthMoon(earthRot, moonRot);

Exercises

1. Camera Experiments

2. Second Planet

3. Model Classes