CS 450 Computer Graphics Animation and Object Hierarchy

CS 450: Computer Graphics Animation and Object Hierarchy

Object Hierarchy Suppose we wish to build a model of an automobile that we can animate. We can compose the model from five parts – the chassis and the four wheels.

Object Hierarchy We could produce such an object with pseudocode similar to the following: { float s; float d[3]; // speed // direction draw_right_front_wheel(s, d); draw_left_front_wheel(s, d); draw_right_rear_wheel(s, d); draw_left rear_wheel(s, d); draw_chassis(s, d); } This code fails to recognize the relationships between the objects. For example, the wheels cannot move independently of the chassis.

Object Hierarchy We can represent the relationships, both abstractly and visually, with graphs. Right-front wheel Left-front wheel Right-rear wheel Left-rear wheel Wheel Left-rear Right-front Chassis Left-front Chassis

Object Hierarchy In Open. GL we used the GL_MODELVIEW matrix to manipulate objects and parts of objects. We explicitly had to push and pop the matrix to allow creation of a hierarchy of transformations In POVRAY each transformation is restricted in scope to the object within which the transformation appears. Each object definition has a set of braces enclosing all attributes and transformations which pertain to THAT OBJECT ONLY.

Object Hierarchy: POVRay A hierarchy WITH A PROGRESSION OF TRANSFORMATIONS can be created by including one object within another and then another, etc. Each enclosing object can have new transformations which modify the entire grouping.

Object Hierarchy: POVRay Use of the #declare and #local statements is quite useful in this process, as they allow association of names with objects. The SCOPE of the two statements are different: - Names created using #declare GLOBAL - Names created using #local are local to the file or { } within which the declaration occurs. You can change the value of a NAME using another #declare or #local but cannot change its type (that's a syntax error). NAMES created this way are very similar to C++ #defines.

Object Hierarchy in POVRay: example #declare Cyan = color blue 1. 0 green 1. 0; #declare Here=<1, 2, 3>; #declare Count=0; // initialize Count union { object { Rod translate Here*Count } #declare Count=Count+1; // re-declare inside union object { Rod translate Here*Count } pigment { Cyan } }

Object Hierarchy in POVRay: example #declare chassis = union{ box { <-1, 1, 0. 25>, <1, 0. 5, -0. 25>} box { <-2, 0. 5, 0. 25>, <2, -0. 75, -0. 25>} texture { pigment { color Blue} } finish{ambient 0. 3} } #declare wheel = cylinder { <0, 0, 0. 125>, // Center of one end <0, 0, -0. 125>, // Center of other end 0. 5 // Radius pigment { gradient y color_map { [0. 0 Black ][0. 5 Gray ] } scale. 25 } finish{ambient 0. 2 } }

Object Hierarchy in POVRay: example // render as five independent objects object {chassis} object {wheel translate <-1. 5, -0. 5, 0. 4>} object {wheel translate <-1. 5, -0. 4>} object {wheel translate <1. 5, -0. 5, 0. 4>} object {wheel translate <1. 5, -0. 4>} // render as one hierarchical object #declare car = union { object {chassis} object {wheel translate <-1. 5, -0. 5, 0. 4>} object {wheel translate <-1. 5, -0. 4>} object {wheel translate <1. 5, -0. 5, 0. 4>} object {wheel translate <1. 5, -0. 4>} } object {car translate <1, 0, 0> }

Animation in POVRay Settings in an INI file or on command line cause creation of sequence of images. These can then be assembled into animations. There is a built-in clock variable. We can use it as a parameter in attribute specifications, transformations, etc. so that each image in the sequence has a new spec or transform applied.

Animation in POVRay: example sphere { <0, 0, 0> , 1 pigment { gradient x color_map { [0. 0 Blue ][0. 5 Blue ] [0. 5 White ] [1. 0 White ] } scale. 25 } rotate <0, 0, -clock*360> translate <-pi, 1, 0> translate <2*pi*clock, 0, 0> }

Animation in POVRay: example The use of clock causes the sphere to move in the X direction, and rotate proportionally so it appears to be rolling across the floor (plane). The clock variable changes automatically from frame to frame. We can make parts of the scene conditional on the changing clock. #if (clock <= 1. 0) do this #else do that #end

Animation in POVRay: example There also other control statements in the POV scene language that we can use to control generation of collections of objects, or to extend the animation capabilities. Here is an example of the #while statement. #declare Count=0; #while (Count < 5) object{ My. Object translate x*3*Count } #declare Count=Count+1; #end

Animation in POVRay: example INI file settings: Set the initial and final frame numbers. POVRAY will generate a sequence of frames between these two values (inclusive). Initial_Frame = 1 Final_Frame = 20 Set the values for the clock. POVRAY will change the clock value in steps appropriate to reaching the final value in the last frame. Initial_Clock = 0. 0 Final_Clock = 2. 0

Animation in POVRay: example //----- testanim. ini ------Initial_Frame = 1 Final_Frame = 20 Initial_Clock = 0. 0 Final_Clock = 2. 0 +Itestan. pov +W 160 +H 120 What is produced? The above pair of files causes POVRAY to create an animation loop that renders 20 frames or images. These are named testan 01. bmp through testan 20. bmp. POVRAY uses the root name of the POV file and numerical digits to name the image files in sequence.
- Slides: 16