Spinball Alexei Kosut Greg Parker Welcome to Spinball, our interactive 3D pinball experience. THE GAME Spinball is targed for Linux, although easily portable to most Unices (and also runs on Mac OS X). It can be compiled using "make", and the resulting (included) executable is named "pinball.linux". It takes the standard GLUT command-line flags. In addition, -g puts activates GLUT game mode (full screen instead of a 800x600 window), and -t activates trackball mode. For the game to run properly, the "tex" and "sounds" subdirectories should be present, with the game's textures and sounds. When run, Spinball will present its splash screen, where you can choose one of two Pinball games by clicking on them. Present are Breakshot (a machine built by Capcom in 1995) and Middle Earth (made by Atari in 1975). Breakshot has more detailed graphics and more advanced gameplay, but both are very playable. After a game is loaded (this may take a few moments), you will be in a 3D pinball table, playing the ball. Unlike real pinball, you can control the motions of the ball directly, as well as being knocked around by external forces such as gravity and the flippers. The controls are as follows: To move the ball use the arrow keys, or if you have a trackball installed, you can use that (the trackball serves as a proxy for the pinball -- as you spin one, so spins the other). Trackball mode can be turned on/off with the T key (this hides the cursor and translates cursor movements into ball control.) The left and right flippers are controlled with the A and S keys, respectively. When a new ball is released, hold down the space bar to pull back the plunger and let go to shoot. The C key switches between camera angles -- there are five angles, including two cameras that follow the ball around, one each from the front and top of the pinball (static views), and one first-person angle from the pinball itself. In the dynamic angles, the M key activates and deactivates an on-screen map. Additional controls: P: turn polygon filling on/off T: turn textures on/off ]: turn lighting on/off Tab: pause game Scoring: Hitting various objects in the game (bumpers, switches, spinners, etc...) will gain points. Falling into the ball trap below the flippers will lose the current ball. After three balls have been lost, the game is over. There is no way to "win", but the object is to accumulate as many points as possible before losing, just as in real pinball. More complicated point-scoring combinations are also possible. For example, the player can earn an extra ball on the Breakshot table by hitting the 'Activate Extra Ball' target in the upper-left of the table, which lights the yellow 'extra ball' light, and then hitting the three dark ball catches in the upper center. REQUIRED FUNCTIONALITY Our game is heavily texture-based. Each object is essentially white, with textures used as decals. The pinball table is built of polygons extruded from a rectangle that serves as the board. The image of the playfield is then textured on to the board and lit to be our game. The ball is a GLU quadrics sphere, with a metallic texture and specular highlights. It has a pseudo-shadow, which is a 50% alpha black sphere projected onto the plane of the table in the direction of the light. Although the "shadow" can be highly unrealistic (especially when the ball gets near walls), it serves the important purpose of making the ball seem part of the game. The camera is movable between five angles, two of which are fixed. The other three follow the ball around from behind. The camera always points at the ball, and attempts to follow the direction: At each frame, a weighted average is computed of the current view direction and the velocity of the ball. That way, the camera smoothly moves to follow the ball, but does not move too quickly. In a game of pinball, where the ball bounces incessantly, it is important to have smooth camera motion. The scene of the pinball table is actually fairly simple to render, except for the texturing (which is quite fast with texturing hardware, and slow without), so no complex techniques are used to simplify rendering, save those OpenGL provides directly, e.g., backface culling. Our user input is fairly straightforward; we accept either keyboard or trackball input of a direction, relative to the view direction, which is turned into a force and fed into the dynamics engine (see below), which controls the location of the ball in the 3D world. The user has control over the flippers and plunger, which are also physically modeled. ADVANCED TECHNIQUES * Collision detection * Simulated dynamics An accurate physical simulation is critical for a realistic pinball game. Spinball's dynamics consist of four primary components: modeling the ball and other objects, detecting collisions, responding to simple bounces, and responding to continuous rolling contact. Spinball's world is 2D. The ball is a circle; everything else on the table is either a convex polygon or a group of convex polygons. Forces and torques may be applied to any object, resulting in gravity, sliding friction, and user input to the ball and flippers. All objects have mass, velocity and other physical attributes that govern their respose to these forces. The collision detection system is relatively simple. During simulation, all objects are moved through some time step. If a collision is detected, the simulator is backed up to a point just before interpenetration occurs, and the information about the collision is given to the collision response system. At no time are objects ever allowed to penetrate. The collision detector relies on two simplifying assumptions. First, the number of objects on the table is small, so a single bounding box around each object is sufficient for efficiency. Second, collisions are always between a ball and something else, never between two polygons. The primary motivation for this restriction is the code complexity for handling multiple arbitrary bounces and contact among concave objects; there was insufficient time to write this code. Simple bounce collisions are handled by instantaneously changing the velocity of the colliding objects. The objects' masses, velocity, angular velocity, and moment of inertia are all taken into account to produce a realistic response. The energy of the colliding objects may also be dampened or increased; most items on the pinball table have a dampening effect on the ball. Spinball uses an analytic method described by David Baraff to handle non-penetrating continuous contact. There are many opportunities for the pinball to roll or rest against a surface, so simulating contact correctly is important. When the ball is resting on a surface, with gravity pulling it down into the surface, the analytic method computes the precise normal force needed to keep the ball from penetrating the surface. This method works even if the ball is in contact with many objects (e.g. trapped on a raised flipper) or in contact with moving objects (rolling down a rotating flipper). * On-screen control panel Part of the screen display is used to convey game statistics: The score is always present in the upper-left hand corner, and in the view modes where the entire playfield is not present, a small map appears in the upper-right hand corner. These are drawn using an orthographic projection on top of the scene. The text uses GLUT's text primitives. The map is drawn using the same code used to draw the actual game (with different drawing options), so it reflects the exact state of the game -- the flippers move, etc..., just as they do in the main view. * Sound We implement sound, where available, using the SL sound library. Sound is an integral part of the pinball game, and we make heavy use of it. Associated with most actions (mainly collisions) is a sound, that is played in the background as the game continues to run. The use of sound is fairly straightforward, with a few exceptions. One of interest is the plunger sound effect: As the player holds down the space bar, the game plays the plunger warmup sound. When the space bar is released, that sound is terminated and the plunger release sound is played. The combination effect is that there appears to be one smooth-flowing sound timed exactly to the user action. If possible, the use of sound when playing this game is highly recommended (although it will run without it). It makes the gameplay much more enjoyable. GAME CONTENT The textures of the pinball tables come from the Internet Pinball Database , which contains information on thousands of pinball games, including photos. We found two games with direct top-down images of the playfield, and used those for our main textures. The 3D model representing which objects were placed where on those playfields, however, we hand-generated. The metallic texture on the ball comes from http://www.pixelpoke.com/, a source of free textures on the Web. The sounds used in the game were extracted directly from the game "3D Pinball" that ships with Microsoft Windows 2000, used without permission. REFERENCES Mathematics of rigid body collisions: Chris Hecker's articles in Game Developer magazine. http://www.d6.com/users/checker/dynamics.htm Code to calculate the centroid of a polygon: "Centroid of a Polygon" by Gerard Bashein and Paul R. Detmer, (gb@locke.hs.washington.edu, pdetmer@u.washington.edu) in "Graphics Gems IV", Academic Press, 1994 Code to solve a linear system of equations using Gaussian elimination: by Ken Turkowski (apple!turk) written 2/16/79, revised and enhanced 8/9/83. via http://www.mit.edu/afs/sipb/project/c++/src/Matrix/gaussian and news:alt.sources Analytic continuous contact algorithm: by David Baraff, http://www.cs.cmu.edu/~baraff/ D. Baraff. Fast contact force computation for nonpenetrating rigid bodies. Computer Graphics Proceedings, Annual Conference Series: 23-34, 1994. D. Baraff. Analytical methods for dynamic simulation of non-penetrating rigid bodies. Computer Graphics 23(3): 223-232, 1989. D. Baraff and A. Witkin. Physically Based Modeling: Principles and Practice. Notes from SIGGRAPH 97 lecture. http://www.cs.cmu.edu/~baraff/sigcourse/index.html