CS 420 Game Engineering 3D
Final Practice Problems
  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. You are representing planets in a solar system using the following scheme: Give an equation that describes the scalar distance between moon m1 and moon m2 as a function of possun, dp1, qp1,dp2, qp2, dm1, qm1,dm2 and qm2,
  4. What is the output of the following fragment of C++ code:
    int &weird(int &x)
      return ++x;
    int main()
      int x = 1;
      int &y = weird(x);
      printf("x = %d, y = &d \n", x, y);
      printf("x = %d, y - %d \n", x, y);
    Bonus question:  If we change the ++x to a x++, then the code will no longer compile.  Why not?

  5. What is the output of the following fragment of lua code:
    1. MyTable = {[1] = 2, [2] = 2, [5] = 1, [6] = 1}
      s1 = 0
      s2 = 0
      for k,v in pairs(MyTable) do
         s1 = s1 + k
         s2 = s2 + v
    2. x = 2
      y = 3
      function twist()
        local x = 7
        x,y = y, x
    3. ft = {}
      ft[1]  = function(x, y) return y,x end
      ft[2]  = function(x, y, z) return z, y, x end
      a, b, c = ft[1](1,2,3)
      d, e, f = ft[2](4,5,6)
      print(a, b, c)
      print(d, e, f)