CPSC 314 (Jan 2006)       Assignment 1 -- Coding

Your goal is to create and animate one or more monkeys using a hierarchy of parts. The best animations will be nominated for CPSC 314 hall-of-fame. The following is a suggested ordering of steps.
  1. [0 marks] Download and compile the template code:
    http://www.ugrad.cs.ubc.ca/~cs314/Vjan2006/a1/a1_code.tar.gz or copy it directly as shown below:
    cp -R ~cs314/Vjan2006/a1_code .
    cd a1_code
    make
    
    Type 'a' to see a very simple arm animation.
    Type 'k' several times to see the keyframes that are being used to create the animation. The keyframes are stored in the file keyframe.txt.
    Type 'q' to quit.

  2. [5 marks] Create a function taperCyl(h,r1,r2,nslides)that draws a ``tapered cylinder'' as a function of the 4 parameters, as shown below. nslices will be the number of polygons used to represent the tapered cylinder, which can be considered to be open on either end. You will be using it as a modeling primitive for some of the body parts of your monkey. For this part of the question, just add a single tapered cylinder primitive to the scene.

    You will be computing all the vertex locations. First use GL_LINE_LOOP in order to draw the tapered cylinder in wire frame. Once this works, compute a surface normal for each vertex and call glNormal3f() before each glVertex3f() call in order to assign a correct surface normal to each vertex, and change to using GL_POLYGON, GL_QUADS, or GL_QUAD_STRIP, thus producing a solid-shaded tapered cylinder.

  3. [4 marks] Build your articulated figure. You should make use of your tapered cylinder at least once in your character. Use an appropriate hierarchy of transformations. Implement it using appropriately structured code. You may want to define separate geometry for each type of link, or you may want to use scaled versions of the various glutSolidX() primitives, where X can be any of Sphere, Cube, Cone, Torus, or Teapot. Draw your monkey in an appropriate ``rest pose'' --- typically this is a simple standing pose. Make your monkey as colourful as you like.

  4. [4 marks] Add the ability to animate your monkey figure by making use of Params[n] variable, where n=2,3, ... to animate the position and joint angles of your monkey. These are animated according to the keyframe data in the keyframe.txt file. Note that the first parameter for each keyframe, Param[1], is reserved for modeling the relative time between keyframes (in seconds).

    Each line of keyframe data will specify all of the ``degrees of freedom of the character''. Below is an example of how you might do this, although I recommend that you come up with your own set of degrees-of-freedom that work for your particular figure and the animation that you have in mind. You could also use this to animate camera parameters, colour parameters, or the movement of other objects. Lastly, you could also use additional keystroke bindings to interactively animate parts of your scene.

    keyframe 0.4 2.0 1.0 10 20 10 10 -20 10 10 40 50 -40 50 10 20
    
    where:
    parameter 1:  time stamp (ignore this for now)
    parameter 2:  body location, x
    parameter 3:  body location, y
    parameter 4:  body lean
    parameter 5:  right hip angle
    parameter 6:  right knee angle
    parameter 7:  right ankle angle
    parameter 8:  left hip angle
    parameter 9:  left knee angle
    parameter 10:  left ankle angle
    parameter 11:  left wing angle
    parameter 12:  right wing angle
    parameter 13:  neck forward bend
    parameter 14:  head forward bend
    parameter 15:  head twist
    parameter 16:  head roll
    

  5. [10 marks] Create an interesting animation for your character. Convert it to an MPEG animation file by dumping PPM images from your application and then using ffmpeg to compile all the individual frames into a single MPEG animation file.

    Because you will need to temporarily create a large number of images that will consume a fair bit of disk space, create a temporary directory /tmp/foo where foo is your user name. Edit the appropriate line in the dumpPPM() function call in order to ensure that image files get written to this directory. Now hit 'd' when running your code and you should get a large number of PPM files being written to this directory of the form imgNNN.ppm, where NNN is the frame number. To convert these image files to an MPEG movie, use

    ffmpeg -i img%03d.ppm -r 24 a1.mp4
    
    Don't forget to delete all your PPM files once your movie has been created. You can play your movie using
    ffplay a1.mp4
    
    If you want to keep your movies reasonably small in size, I recommend choosing an appropriate window size for your animation. For example, a 500 x 300 video will be approximately 1/4 the size of a 1000 x 600 video.

Hand-in Instructions