Ratko Jagodic
Computer Animation - Fall 2006
The point of this game is to put the letters into their corresponding corners as quickly as possible. There are many influences on the boids but the main one you can use are magnets, one for each type of letter. The letters can be set in the text file but you can use only a,b,c,d and up to 4 different kinds at a time.
Anim8or - for all the models (letters, magnets, paper, corners)
Python - for game logic, parsing input file...
Panda3D - for graphics and scene graph (meant
for use with python)
The main components are:
Boids
All the boids are simple lowercase letters that are loaded once and instantiated
any times as needed. The rules that control them have been implemented as per
Craig's flocking rules. The boids only detect collisions with the lines and
all other movement is influenced by the following:
Paper
Paper is just a simple box with a texture on it. It's also the parent for every
other object in the scene graph because every object is supposed to be on the
paper. Instead of detecting collisions on the paper itself, there is an infinite
collision plane on the paper because that way we can get picking outside the
paper area (useful for controlling magnets with a mouse). The paper is constantly
swaying a bit in order to further influence boids.
Magnets
Magnets are a primary way of attracting and dragging boids into their
corners. There is one magnet per letter and it only attracts that letter. However,
it also repels all other letters which makes it harder to grab certain letters
out of the group (because your letters will try and follow all the other ones).
Magnets only have collisions set up with the collision ray which is the main
picking object (a ray shot out from the camera onto the paper collision plane).
That's how the dragging is implemented. Basically a ray is shot from the camera
into 3D space from the 2D mouse position. Wherever the ray intersects the plane
that's the new position for the magnet. The magnets themselves don't influence
the boids unless they are "held" (clicked on and dragged around).
This is done so that we can't just position them in the space and let the boids
eventually converge around them.
Corners
Corners are the target location for each boid type. However, the boids
will not go there by themselves. Only when the corresponding boids are close
enough will they get sucked into the corner and disappear. The problem is that
all other boids are repelled by the corner so they will try to pull the corner's
boids away from it. That's why just letting the boids fly around will not eventually
place all the boids in their corners. Some user action is required with the
magnets. There are no collisions with the corners, only the distance from the
center of the corner to each boid is measured and if below a certain treshold
the boids will get sucked in. There is also a distance defined under which it
influences opposite letters and a different (smaller) distance under which it
starts to influence the like letters. Once a boid is "sucked into"
the corner it will rapidly scale to 0 at which point it is removed from the
scene graph.
Lines
Lines serve as temporary barriers for separating groups of boids. They
can be drawn on the paper with the cursor but they disappear automatically after
3 seconds. There can be only one line on the paper at the time and if you attempt
to draw one before the existing one disappeared, the first one will be deleted
instantly. The lines actually detect collisions with the boids. If a collision
occurs, the boids velocity is inverted so that it goes back to where it came
from... but only for a short while. Also, while it's velocity is inverted, there
are no other influences on the boids and instead the same velocity vector is
applied over and over (but this only happens for a very short time... to be
precise just enough to get the boid out of the object that it collided with).
Bins
The whole paper area is subdivided into bins and then each boid is
placed into one bin. As boids move, their bin membership is updated. When the
boid is looking for its neighbors, it only looks in the neighboring bins as
opposed to measuring distance to the neighboring boids. This is somewhat different
from the Craig's boids because he picks neighbors in nearby bins based on the
actual distance. So, he might not pick every boid from a certain bin. My algorithm
would actually take all the boids from the nearby bins in order to save a few
extra comparisons without sacrificing the visuals. This whole binning process
is done in order to break the polynomial compexity of the neighbor-searching
algorithm. All the bins are of equal size except the ones on the edges which
are infinite in that one direction. The reason for that is that boids that go
"out of bounds" can still come back by orienting themselves towards
the boids in the neighboring bins. The bin representation in the game does not
actually show the edge bins as being infinite. Experimentation with the grid
size showed that 15x15 for this purpose seems like a good balance between the
performance improvement and the realism of the flocking.
This has only been tested on Windows even though it should technically run
on Linux as well.
Python is included with Panda3D so you dont need to download it separately.
SOURCE:
EXECUTABLE:
GAME INSTRUCTIONS:
(Javier Iparraguirre) - How does the wind affect
the boids?
The wind is used for moving the boids due to the paper swaying back and forth.
I basically set the direction of the wind to the vector of the paper swaying
direction and set some magnitude to limit how "strong" the wind is.
(Joshua Buss) - How did you determine if the boids are hitting the edge of the paper?
Some seemed to be able to escape.
I didn't try to keep them strictly on the paper on purpose. I wanted them to "bounce off the wall" smoothly so instead of abruptly changing their direction I would slowly subtract some speed from their velocity until they were back on the paper. If you keep subtracting a small amount each time you will eventually reverse their velocity. Also, this rule is applied after all the other ones but still before the speed limiting.