This is an OpenGL simulation of a body of water using a mesh of springs. It also simulates reflection and refraction. It's written in C++ using GLUT. Mac and Windows binaries are provided.
This is a set of classes taken and adapted from one of my projects (so some of it is a bit out of context). It consists of a data structure for organizing objects into hierarchical trees. Individual nodes can be in more than one tree simultaneously (have more than 1 parent), hence "Multi"-Node.
The interesting thing (I think) is the iterator class (defined in MultiNode.h, used in main.cpp). I found I often needed to scan sections of a tree and perform operations on nodes matching some criteria (ie. sort of a combination of STLs find_if and for_each algorithms). However, I've never liked the style of for_each because the operation is always separated from its use (the code that does the work is never in the same place as the loop control). eg:
for_each (start, end, functor_defined_somewhere_else)
I almost always wanted to do something simple enough and specific enough not to warrant a totally new function, but doing the iteration by hand every time is messy and error-prone, so I built a predicated iterator that enabled me to retain the structure of a traditional for-loop:
for (/* loop control */) { /* operation */ }
Specifically, it allows things like:
for (tree_iterator i (root, SomePredicate); i; ++i) { i->SomeOperation(); i->AnotherOperation(); }
This way the iteration mechanics are factored out and kept together, and the body of the loop is devoted to the operation. I've found this to be a useful tool when dealing with my object hierarchies. It allows for very complicated iterations to be represented clearly with all the appropriate parts abstracted.
Henry Smith
henry@enigmasoftware.ca