
SCEA Developers Conference 2002 VU Coding Contest Entry by Matthew Scott

This demo is an application of some rigid body dynamics research that I have
been doing at Monolith Productions.  It is primarily based upon work presented
by Thomas Jakobsen of IO Interactive in the paper "Advanced Character Physics".
The paper can (at one point in time) be found at:

http://www.ioi.dk/Homepages/tj/publications/gdc2001.htm

The biggest thing about making this source code public is that it removes all
the mystery.  To me, a great game/demo is about believability / immersion.  The
person playing the game has no idea how you actually implemented the game; they
will not be impressed with an algorithm.  Therefore, please keep two things in
mind. First, although simple, this algorithm produces very nice, believable 
results.  Second, this is not a sample of how to write efficient VU code.
Limited by space and wanting to complete the demo quickly, the easiest route
was always taken which (as often is the case) leads to less efficient code.

Enough of the excuses, on with a description of this demo.

What is What:

marionette.vcl VCL code executed by the contest harness
marionette.dsm dsm file that includes the VCL output (vsm)
marionette.hlp Help file for the harness
makeimage.cpp  C file that produces the data image loaded to VU data mem.
pack.cpp       C file that deals with the binary strip data
pack.h         Header file for pack.cpp
body.msh       binary chunk of strip data used for the two body parts
limb.msh       binary chunk of strip data used for all the limbs

There is a Makefile that will build and install everything in to the harness
directory and even launch the harness.  You will need to modify the harness data
file to recognize any demos other then the ones that come with the harness.

I used VCL version 1.27a and obviously all of the entry was written using VCL.
My use of VCL was one of the main reasons that I was able to complete my entry
in a timely manner.  Having to do all of the processing on the VU means that
there is a bunch of temp variables and the register naming was a real time
saver.

There is a memory map at the beginning of marionette.vcl that describes the
format of the dat file that makeimage produces.

The basic algorithm used is to maintain a group of particles that are moving
in space and then apply a set of constraints to that motion.  These particles
are then used as the skeleton of the marionette model.  The model is really
just two pieces: a limb and a body.  These pieces are then instanced, oriented 
and scaled.

Code Overview:
line 117 - 136  Load trans and light matrix
line 137 - 193  Set up world->view based on "matrix mode" or normal mode, in
                matrix mode a rotation about the origin is performed
line 194 - 212  Build world->screen
line 220 - 245  Accumulate the forces on each particle and calculate its new
                position
line 249 - 428  Read the pad info to get motion amounts (and other stuff)
line 430 - 550  Move the 5 control points based upon motion amounts, constrain
                the motion to the bounding volume (the room).
line 552 - 638  Constrain the particles using the stick constraints and bounding
                volume (the room).
line 644 - 702  Render the skeleton and strings
line 705 - 886  Render the meshes for each limb/body piece.  The tricky part is
                getting the local->world for each piece.  The translation
                component is easy, but the orientation is a bit hard.  There is
                a lot of code here to get the basis vectors for the orientation.
                Finally, the scale is baked into the data
line 889 - 967  Render the room she is in
line 970 - 1275 Render shadows.  Since the light doesn't move I know the three
                planes that the shadows can fall onto.  Therefore, just repeat
                3 times adding a parallel projection from the light onto each 
                plane and render everything as black

That's it.  Enjoy.  If you have any question or comments please send them to
matt@escapefactory.com

Thanks,
Matt

