Object Animation CMT3317
Do you need to do animation? We consider ways of animating composite objects – that have a number of different parts e.g. a person, a tank You may want to do this for the second cswk or not – depends entirely on you and your game design
We consider Model cycling –Easiest to do, very simple, most likely to be used Articulated model animation –A bit harder, a bit better, more work, might use it Animating a skinned boned model –A lot harder, needs good animation skills, the best, but no simple demonstration, unlikely to use it
Model cycling Just like 2D image cycling (e.g. using sprite sheets) but uses 3D models instead Create a number of models and render the appropriate one at the appropriate time
Class ModelCycleObject This class is similar to the AnimatedSprite class It has a list of 3d models that it uses for animation It is used to build a green guy, who can perform a number of behaviours depending on his current state
Finite state machine of a GreenGuy
ModelCycleObject In the walk state he walks a distance down the z axis cycling between left walk, standing and right walk models In the jump state he does two continuous jumps In the look state he merely billboards to look at the camera In the sleep state he rotates increasingly position while flipping between two sitting models In the dead state the dead model is drawn
ModelCycleObject – class variables
ModelCycleObject – Update
ModelCycleObject – look
ModelCycleObject – jump
ModelCycleObject – sleep
ModelCycleObject – walk
Look at GreenGuys1.zip
Green Guys In this step a manager class that holds an array of green guys is created A bounding sphere variable is added to the ModelCycleClass to enable collision detection You can then drive over the green guys in the car
Green Guys Collision detection is done in the Game1.cs Update() function after reading input and possibly having moved the car, and updating the guys Look at GreenGuys2.zip
Synchronised guys
Unsynchronised
Articulated Object Animation Objects made of rigid segments which can rotate at their joints, like people Segments lower down the chain inherit the rotation and translation of segments higher up E.g. if you move your thigh your shin and foot will also move Such objects are hierarchies, the top of the hierarchy is the root, other segments are children
One legged teapot
Forward kinematics In forward kinematics animation is achieved by starting at the root and descending the hierarchy applying transformations on joints as you go This is tedious from a programming point of view you may well be happier just using model cycling if you need animation Tedious because nearly all transformation sequences are non-linear and hard to model in a program
Create a model Use Max to create a model, e.g. a leg Shown in left view, with a blue thigh, green shin, and orange foot
Procedure You need to set the pivot points for each component correctly You need to save components individually Save your model in MAX format first
Thigh pivot point Thigh pivot point needs to be at top of thigh Therefore position it with the top over the origin in MAX Delete the shin and foot to save the thigh individually, export to.x format
Shin Reload the leg, delete the thigh and foot Move the shin up over the origin in the top view to set the correct pivot point Process foot in a similar manner
Body Articulated object hierarchy needs a root object Create a torso for your leg to attach to In this case we used a teapot for convenience We create a class TorsoTwoLegs (which will be a torso – the teapot- which will have two legs for walking But first we need a class to represent a node in an articulated heirarchy
Class ArticulatedObjectNode A node in an articulated model can either be a root node or a child node This class is subclassed from SimpleObject and has a variable ‘parent’ to store its parent node The parent for the root node is set to null, the parent node for a child will be set to that child’s parent This class also has a matrix for its own rotation and another matrix to store the rotation of its parent
Class ArticulatedObjectNode
The class has a function to set the parent node In the classes’ Draw() function if the node is the root node ( its ‘parent’ variable is set to null) it draws as usual Otherwise it multiplies on the parent matrix before the child transformations
Class ArticulatedObjectNode
The class has a function to make it translate along the path of a circle The teapot will be simply translated whilst the legs will be animated to simulate walking The class has a function to rotate around the x axis as this is how the thighs and knees will be animated – around the local x axis
Class ArticulatedObjectNode
Class TorsoTwoLegs Having defined the class needed for an articulated structure, and 3D models needed We need a class to represent the walking teapot and to implement it’s animation It will have a torso, and a thigh, shin, and foot for each leg (are defined as class variables are counters needed for animation)
Class TorsoTwoLegs
Initialise Recall that the leg components were moved to the origin in MAX to set the pivot points Therefore we need to translate them to their correct positions in the program We can work out where the objects end by checking in MAX
Object size in MAX Put cursor a point where new object will join in top window At the bottom of the screen the 3 numbers to the left of grid show the cursor position E.g the bottom of the thigh is at ~-23 in the y from the origin
Initialize()
Update() A function is defined to make each component walk, called from the update function The feet aren’t animated so there are no functions for them
Animate the torso Only the torso is allowed to translate, it ‘drags’ the legs along with it The torso makes the object walk in a circle by rotating and translating
Animate leg components Each of the leg components had to perform local rotation around it’s axis A local static variable is defined and used as a counter, –e.g. the thigh rotates -4 degs for first 15 cycles 4 degs for next 15 cycles 2 degs for next 15 cycles -2 degs for next 15 cycles
Animate leg components Other leg components are dealt with in a similar way The result is reminiscent of walking or skating Hard to get right by programming Transformation sequence should be non- linear rather than linear
Continuous Animation Results
See Articulated.zip
Skinned Mesh A skinned mesh is a mesh which has been animated with a bone system A bone system is an articulated hierarchy (as described earlier) However the bones are not rendered, the mesh is linked to the bone system Allows the mesh to be stretched and deformed naturally Look at the skinned mesh example D3D8 program
Bones, bones and mesh, skinned mesh
Skinned Mesh The D3D example was created with the Character Studio plugin Which allows you to easily animate bipeds Support for keyframe animation is provided in D3D via Animations and AnimationSets You are unlikely to be able to get on top of this material in time for the cswk.