Game Development Reference
In-Depth Information
Figure 6-5. A typical screen shot for the Linear Collision Simulator
The spheres are modeled such that they are not subject to gravity or any other force. In
addition to fields representing the GUI components, the SphereCollision class declares fields
that represent the location, velocity, and mass of the spheres and the coefficient of restitution
between them. The x-locations represent the locations of the center of each sphere.
import javax.swing.*;
import java.awt.*;
import javax.swing.border.BevelBorder;
import java.awt.event.*;
import javax.swing.Timer;
public class SphereCollision extends JFrame implements ActionListener
{
// GUI component declarations not shown …
// These fields store sphere data and the coefficient
// of restitution.
private double vx1;
private double x1;
private double mass1;
private double vx2;
private double x2;
private double mass2;
private double e; // Coefficient of restitution
private double sphereRadius; // Radius of spheres
Search WWH ::




Custom Search