Squirtgun Shooting Gallery
Overview
Basically, this game is a fun way to play around with a particle system based water simulation. The user attempts to knock over targets in the shortest time possible. The game is fully textured and every element is physically modeled.
Instructions
To play the game, run ./spray. For fullscreen mode, run ./spray --fullscreen. In-game controls are simple: control the squirt gun with the mouse and use p to pause. The mouse moves the back of the squirt gun, which rotates around the business end of the barrel.
Controls
Key | Function |
ESC | Exit the simulation. |
p | Pause the simulation. |
Left click | Shoot water. |
Mouse movement | Aims the squirt gun. |
Implementation
The program makes use of several libraries for graphics, control, and physics operations. SDL provides mouse and keyboard control along with windowing functions. OpenGL, GLU, and GLUT are responsible for 3D graphics. ODE is employed for rigid body dynamics and collision detection with the exception of particle physics. These are handled internally for better control and performance.
The game world is laid out within a box, half of which contains a shooting gallery. Within the shooting gallery, there are a number of platforms, and on these are targets. Each object in the world has a graphical and physical representation, including collision bounding shapes.
Particle System
The game's particle system dynamics are implemented independently of ODE for better performance. A typical particle's life would go something like this:
- The particle is created along with its brothers and sisters, who are being generated by the thousands via a WaterSpraySystem at a user-defined constant rate. Its color, starting position, and velocity are randomly generated based on preset prototype particles.
- It continues along its path, updated independently of ODE based on the same forces acting on ODE world objects.
- An obstacle is encountered! Our particle's collision with this obstacle is detected by ODE's collision system and resolved by the particle system as follows:
- If the magnitude of the particle's velocity projected onto the collision normal is above a certain threshold, then the particle bounces off of the object. First, a random variation on the normal vector is calculated and scaled to match the incoming particle's velocity. Then, an ideal kinematic response vector is calculated as described in the Parent text on pages 217-219. These two vectors are weighted and combined to form the new particle velocity.
- If the magnitude is less, the droplet sticks to the surface and continues to slide along it.
- These rules combine to form a very good looking water splashing effect.
- A momentary force is then exerted on the obstacle object from the point of collision. Its magnitude is proportional to the original velocity of the water particle. Due to the unique nature of particle vs. nonparticle collisions, the relative velocities and masses can be neglected for better performance.
- The little particle is all grown up now, and starting to show its age. Its color is gradually turning whiter to simulate more air bubbles in the spray.
- Sadly, it has now reached the end of its life after a predefined number of seconds. The particle disappears and is deleted from the system.
Targets
Targets appear as cardboard boxes with paper bullseyes stretched over the front. The user attempts to knock these over. For each cycle of the game, the quaternion representing the target's rotation is examined. If the box is rotated enough from its original position, the target starts dying. Eventually, the ball with withdraw from the physical simulation and shrink out of existence.
Screenshots
The initial gallery setup.
Water splashing off of a wall.
A doomed target blinks out of existence.
Oh, the humanity!
A sideways shot knocks a target off of its platform.
Everybody has made water spirals with a hose before. It works here too.
$Id: index.html 444 2006-03-22 17:34:11Z jstrater $