CS 486/686 Game Engineering
Practice Problems #3
  1. You want to point your camera at an object.  You want the camera be as close as possible to "right side up", given that it is pointed at the object.  That is, you want the camera's up vector to be as close as possible to the world up vector, given that the camera is pointed directly at the object.  If the object has the position po = [pox, poy, poz], and the camera has the position pc = [pcx, pcy, pcz], give the rotational matrix for the camera.  


  2. You want to aim a turret.  The turret consists of two objects:  The "base", which can rotate around the y axis, and the barrel, which can be raised or lowered:

    Turret Image


    The barrel is attached to the turret (so that it moves when the turret moves).  The barrel is attached at an offset of [0,0,0] in turret space (so the origin of the barrel is the same as the origin of the turret).  Assume that if the rotational matrix of the barrel (in turret space) is the identity matrix I, the barrel points straight down the z-axis of the turret.

    You wish to rotate the turret and raise the barrel so that it points at an object at position p = [px, py, px].   Show how to create the rotational matrix for both the turret (in world space) and the barrel (in turret space).   Feel free to define "local variables" in your answer (such as, let x = || p1 × p2||)

  3. Recall the solar system definition from the second midterm.  We are going to extend it a little bit.  We have:

  4. What is the output of the following fragment of C++ code:


    int &wierd(int &x)
    {
      return ++x;
    }

    int main()
    {
      int x = 1;
      int &y = wierd(x);
      printf("x = %d, y = &d \n", x, y);
      y++;
      printf("x = %d\n", x);
    }

    Bonus question:  If we change the ++x to a x++, then the code will no longer compile.  Why not?