next up previous contents index
Next: Background and Foreground Up: Affects Previous: Manipulating a Scene within

PointAtAffect

One Affect is the PointAtAffect   class which is defined in Mirage and is used to point one object at another.

This affect is the default way of positioning the camera by pointing the camera at a camera focus.

The example shows a magic ball which flies around above a wand. The ball and wand are labeled and bound at the origin. The wand is pointing towards the positive X axis. 

  // Add a ball for the wand to point at.
  vector ball_centre ={0, 0, 0};
  double circle_rad = 3;
  double flight_height = 1;
  Vector::assign(ball_1position, ball_centre[X]+circle_rad *sin(worldtime*PI),
          ball_centre[Y] + circle_rad * cos(worldtime*PI),
          ball_centre[Z]+flight_height *sin(worldtime*3*PI));
 
  object ball = scale(0.4,new_sphere());
  ball->material = dkred;
  ball->label("ball-label");
  LINK(the_scene, PLUS, shift(ball1_position, bind(ball)));
  object ball2  = scale(0.4,new_sphere());
  ball2->material = gold;
  ball2->label("ball-label");
  LINK(the_scene, PLUS, shift(ball_1position, bind(ball)));

  // Create the wand pointing along the x axis
 object star = bind(rotate(Z, Y, 90, stretch(1.0, 1.0, 0.1, 
                    shift(-0.5,-0.5,-0.5,new_extrusion("star.pgm",TRUE)))));
  star->texture =  new ImageTexture(0, "gold.ppm",
                                    X, -0.5, 0.5,
                                    Z,  0.5,-0.5, SINGLE, OPAQUE, 
                                    TRUE, FALSE, FALSE);
  vector wand_position;
  Vector::assign(wand_position, 0.2*noise_1(fmod(worldtime,1)+6), 
                 0.15 * noise_1(fmod(worldtime,1)), 
                 0.18*noise_1(fmod(worldtime,1)+7));
  object wand = bind(rotate(Z, X, 90, shift(0, 0, -0.7, 
                     stretch(0.07, 0.07, 2.5, new_unitcyl()))));
  LINK(wand, PLUS, shift(2.0, 0, 0, bind(star)));
  wand = bind(wand);
  wand->material = black;
  wand->label("wand_label");
  wand->affect = new PointAtAffect("wand_label", "ball-label");
  LINK(the_scene, PLUS, shift(wand_position, bind(wand)));

 figure512
Figure 20: Magic Ball: PointAtAffect

Another affect that is standard in Mirage is the HugHeightfieldAffect. This is explained in 17.1



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