Since some types of fish found in reef aquariums school together,
it was necessary to add this behavior to the OpenGL Reef Tank. It's
handled by a simple set of rules, described here. First, some definitions:
School center: The average position of all of the fish of
a given type at a given time.
School radius: A distance from the school center within
which a fish is "in the school". This radius is the same
for all fish of a given type.
School velocity: The average velocity (speed and direction)
of all of the fish of a given type that are in the school
at a given time.
Now, the rules:
- If a fish is outside the school radius, it will swim towards
the school center.
- If a fish is within the school radius, it will swim at the
And that's it. There's a bit of randomness thrown in for some flavor,
but those two rules, along with some collision avoidence to keep
the fish in the tank, are enough to keep the fish and the school
moving around the tank in a fairly realistic looking way.
This schooling method may not scale to a large number of fish,
however, since a large number of fish would be trying to crowd into
a small school radius. Increasing the school radius may solve the
problem, or perhap changing the behavior to be based on relative
distance to the closest fish of the same type, rather on the distance
from the school center. Some testing on this still needs to be done.
Here are a couple of screen shots:
It's a little hard to tell what's going on there, but the yellow
and red lines run from the fish to the school center. If the line
is yellow, that means the fish is in the school; red means it's
too far away. The green lines pointing out of the fish indicate
the school velocity.