3D Space in GeoGL

General

   This is the introductory paragraph

Camera movement

   To create a 3D world, one or more cameras are required. The Camera3D class manages camera position, and orientation. It is built upon the GeoGL vector and matrix classes. Methods are provided to set camera position and direction, to rotate the camera relative to its current direction; to compute forward, up, and right directional vectors; and to execute OpenGL commands.

   To define a camera, declare a Camera3D object. The camera will default to the origin(0,0,0) facing along the negative Z axis (0,0,-1) with up along the negative Y axis (0,-1,0). The camera can be returned to this position at any point by calling the reset() method. The simplest way to start the camera in another position is through the lookAt(...) method. This method sets the position, direction, and rotation of the camera.

    Once the camera is setup, you must apply the camera to the scene. In OpenGL, this is normally done by appling a series of translation/rotation commands to the model-view matrix, or using glMultMatrix(). The camera3D class will perform these matrix transforms when you call the execute() method.

Camera examples
// A camera to manipulate
Camera3D cam;

#define MOVE_SPEED 1.5f       // Increase to move faster
#define TURN_SPEED 1.5f       // Increase to turn faster

// Move the camera to an arbitrary starting position/orientation
void initialize()
{
   fVector3D position(3,-14,15);   // Position the camera at (3,-14,15)
   fVector3D lookAt(10,20,30);     // Point the camera at (10,20,30)
   fVector3D up(0,-1,0);

   cam.lookAt(position,lookAt,up);
}

// Process the key that was just pressed
void processKey(int nKey)
{
  switch(nKey)
  {
      // Strafing movement
      case 'W': cam.position += cam.getForward() * MOVE_SPEED; break;
      case 'S': cam.position -= cam.getForward() * MOVE_SPEED; break;
      case 'A': cam.position += cam.getSideways() * MOVE_SPEED; break;
      case 'D': cam.position -= cam.getSideways() * MOVE_SPEED; break;
      case 'Q': cam.position += cam.getUpward() * MOVE_SPEED; break;
      case 'Z': cam.position -= cam.getUpward() * MOVE_SPEED; break;

      // Rotations
      case VK_UP:       cam.rotateXdeg(-TURN_SPEED); break;
      case VK_DOWN:     cam.rotateXdeg(TURN_SPEED);  break;
      case VK_LEFT:     cam.rotateYdeg(-TURN_SPEED); break;
      case VK_RIGHT:    cam.rotateYdeg(TURN_SPEED);  break;
      case VK_INSERT:   cam.rotateZdeg(-TURN_SPEED); break;
      case VK_DELETE:   cam.rotateZdeg(TURN_SPEED);  break;
   }
}