Lev's personal webpage

26Jul/11

Treebe Universe!

Treebe is a program I have made a while ago, sometime in 2006, for a computer graphics class. I was learning OpenGL and relative coordinate system, so as an exercise I decided to write a screen-saver type program that would display a lot of objects in a recursive pattern utilizing relative coordinates via OpenGL's modelview matrix stack. I chose a pretty basic pattern of a parent object surrounded by 6 smaller children on each side. By changing relative position between parent and children I added animation.

I have also created a simple polymorphic scene-graph API to make the code more generalized and somewhat elegant. This scene graph is actually a tree (here is where Treebe name originated) where each child inherits from a base class - ANode, that represents a node in the scene. ANode has enough information to link to children and to describe their relative size, position and rotation to the parent. It also has a field for a display list (which made displaying lots of object a LOT faster) and a default virtual render() method that calls display list (unless it is overridden by a child class).

Simple pre-order traversal of the tree (call render() of each node before going to children) renders the whole scene. To animate Treebe specifically I only needed to make another tree traversal function that added same offset to each node which is a sinusoidal function (thus the whole thing expands and shrinks). As you can see from screenshot, several geometric objects can be used for each node which is done by another traversal that sets the display list id for each node. By twiddling with the default relative size of child to parent it is also possible to achieve different looking "orbits" (as example compare 2nd and 3rd screenshots).

Windows executable download

Controls:

1-8 Change display list.
q, e Increase/decrease relative scale between parents and children.
-, shift + Decrease/increase recursion depth.
space Pause animation. Press again to step through it.
n Continue animation.

Screenshots:

Filed under: Programs Comments Off
Comments (0) Trackbacks (0)

Sorry, the comment form is closed at this time.

Trackbacks are disabled.