next up previous contents index
Next: Components of a Camera Up: Creating a Mirage Scene Previous: Making an Object into

Viewing the Scene: The Camera

   

Every scene needs a camera to render it. You can have several cameras in a scene, but only one is used for any given frame. The routine make_<project_name> has one parameter active_camera. You must set active_camera to point to the camera that you want to generate the picture for this frame. 

  *active_camera = the_camera;

Cameras are initially positioned at the origin looking towards the +ve X axis. The direction the camera is viewing in can be changed using rotate commands, or you can create an object for the camera to point at and use PointAtAffect to point the camera at the object. Affects are explained in Section 13 but all you need to do is define camera_position and focus_position in the newmirage project code as it uses the PointAtAffect method of orienting the camera.

Code for initialising and positioning the camera and focus position: 

  object the_camera, camera_focus;
  vector focus_position = {0, 0, 0};  //The camera points towards this. 
  //The focus point is only important for the direction of the camera.
  //All the objects will be in focus.
  vector camera_position = {4, 4, 0}; //The camera is here.

  // Add an object for the camera to point at. Provides an 
  // intuitive way of positioning and orienting the camera.
  camera_focus = new_nothing();
  camera_focus->label("focus-label");\index{label}\index{PointAtAffect}
  LINK(the_scene, PLUS, shift(focus_position, 
       bind(camera_focus)));

  // Create the camera. Image size may be modified by the 
  // parameter picture-size in the keyfile <projectname>.key.
  the_camera = new_camera(new PinholeOptics(20.0, 1),
                          new StandardRayTracer,
                          new Antialiaser(0),
                          new ColorStorage,
                          NULL);
  the_camera->label("camera-label");
  the_camera->affect = new PointAtAffect("camera-label", 
                                         "focus-label");
  LINK(the_scene, PLUS, shift(camera_position, 
       bind(the_camera)));





Sophie Day
Fri Feb 20 15:47:19 NZDT 1998