Daniel Kohler
16 March 2010
This program uses C++ and OpenGL to render a scene that animates a cartoonized life-cycle of flowers. The scene is composed of a ground plane with grass texture, a sky box with a cloudy sky texture, and flower objects that appear, grow, die, disappear, and re-appear at a new random location. The world may be explored in first person.
Foreground: a red flower in full bloom. Mid-ground: a white flower in the early stage of death. Background: a white flower in early stage of growth.
Foreground: a red flower mid-growth, just beginning to bloom. Background: a white flower early-mid-growth, prior to bloom.
A white flower in mid-bloom.
A red flower in mid-bloom.
Foreground: a red flower in mid-stage of death. Background: A red flower in early stage of death.
Lots of happy flowers.
Lots of less-happy flowers. :|
The user has the control to move the camera position and direction in the world.
Click-and-drag to look around in the style of a first-person shooter. Vertical view angle is limited to 45 degrees from the horizontal plane.
The crux of this program is the animation, which relies on the hierarchical relationship between graphical objects. One of the first steps in writing this program was to define a drawable
structure. This structure contained information on how to graphically represent a single, simple object on the screen, including geometry, texture, and lighting properties, as well as position and orientation. It also contains a link to a parent and to multiple children, which are the key to hierarchical modeling. The following two tables describe the structs used in this program for hierarchical modeling and animation.
Data Type | Member Name | Description |
---|---|---|
Vector3 | center | Coordinates of the object's center, in object geometry space. |
Vector3 | irotAxis | Initial rotation axis about object's center. |
float | irotAngle | Initial rotation angle. |
Vector3 | position | Object's position in parent/world space. |
Vector3 | rotAxis | Object's rotation axis about object's center, after initial rotation. |
float | rotAngle | Object's rotation angle, after initial rotation. |
Vector3 | size | Not to be confused with 'scale'. Size is used when the shape is a geometric primitive. It determines length, width, height, radius, etc... This variable does not affect scale of children. |
Vector3 | scale | Scales this object and its children. |
int | shape | = 0: cube (l, w, h: size) = 1: sphere (radius: size) = 2: mesh (see thisMesh) = 3: leaf = 4: red petal = 5: white petal |
materialStruct | material | Contains RGB values for ambient, diffuse, and specular lighting, and the degree of shininess. |
mesh * | thisMesh | In the case that shape = 2, thisMesh contains geometry including vertices, triangles, surface normal vectors, and vertex normal vectors. |
drawable * | parent | Link to parent object, if applicable; otherwise NULL. |
vector<drawable *> | children | Links to all children, if applicable. |
void | draw() | 1. Performs all transformations previously described. 2. Calls appropriate drawing helper function. 3. Calls the draw() functions of all children. |
Data Type | Variable Name | Description |
---|---|---|
drawable * | stalk | This flower's stalk. |
drawable * | leaf1 | This flower's larger bottom leaf. |
drawable * | leaf2 | This flower's smaller, top leaf. |
drawable * | bud | This flower's bud (red or white) |
drawable * | petals[6] | This flower's six petal objects. |
int | thisStartTime | The time in program animation milliseconds. |
void | doAnimation() | Sets the scaling, rotations, and positions of the stalk, leaves, and petals, as a function of this flower's animation time relative to thisStartTime. |
void | start() | 1. Resets positions, orientations, and scales of all flower members. 2. Sets thisStartTime to current animation time. |