Homework 6

As we discussed in class, it is possible to define a simple assembly language for specifying movement of jointed computer graphic figures.

Your next assignment is to implement such a motion machine. Your machine should have the following instructions:

where value can be either a constant or a time varying variable. Your implementation should include a method eval(int varId, double time) which the motion machine can call to access variable values.

The rotate and translate instructions should be cumulative, and be in local coordinates. For example, if you've previously done:

rotate y pi/2
then a subsequent
translate x 1
should actually effect a translation in the z direction.

You need to implement the following methods, which constitute an API to the machine:

   boolean push();
   boolean pop();
   void rotate(int axis, int var_Id, double constant);
   void translate(int axis, int var_Id, double constant);
   void drawBox(double xLo, double yLo, double zLo, double xHi, double yHi, double zHi);
   double eval(int var_Id, double time);
The push and pop routines should return false if they overflow or underflow the matrix stack, respectively.

In the call to rotate or translate , if var_Id is negative, then interpret the argument as a constant, and use the last argument constant .

All rotations should be in units of radians.

The motion machine should be called at each frame of an animation, with time varying inputs, to create animations. To implement the motion machine, I suggest maintaining a matrix stack, implemented as an array of matrices.

Initially, you'll want the stack pointer sp to be set to zero (so that the stack has only item in it), and you'll want stack[0] to contain the identity matrix.

You can implement push as follows:

   if (sp+1 == stack.length())
      return false;
   stack[sp+1] = stack[sp];
   sp++;
   return true;
and pop as follows:
   if (sp == 0)
      return false;
   --sp;
   return true;
Try making a simple model of a human, as we discussed in class, and animating it. For now, you can just use time-varying sine curves within eval for rotating the joints. This will produce nice smooth movements as the limbs animate.