Game Development Reference
In-Depth Information
Figure 8-9. If the rpm exceeds 8000, you've blown the engine.
The GUI for this car simulation is pretty primitive, but the physics inside it are real and are
based on the equations developed in this chapter. The effects of aerodynamic drag and rolling
friction are included in the model. Some simplifications were made, however. The car is assumed
to be driving in a straight line on flat ground. When the car is braking, the acceleration due to
braking is assumed to be a constant -5.0 m/s 2 at all times. We are also not modeling the reverse
gear in this simulation, so the car is either stopped or is moving forward.
The tires of the car in the Car Simulator are assumed to roll without slipping at all times. In
real life, if too much torque is applied to the wheels, the maximum frictional force between the
tires and the ground will be exceeded, and the tires will slip along the ground—the “burning
rubber” effect. We'll explore how to model tire slippage in more detail in the “Wheel Traction”
section a little later in this chapter.
Creating the car simulation requires two general types of classes—one representing the
car and the other defining the GUI. We'll start by discussing the classes that represent the cars.
Two car classes will be written. The first class is called the Car class and represents a generic
car. The Car class will declare the fields and methods that are common to all cars. The Car class
will be written as a subclass of the DragProjectile class so it can reuse the code declared in the
DragProjectile , SimpleProjectile , and ODE classes.
public class Car extends DragProjectile
{
private double muR;
private double omegaE;
private double redline;
private double finalDriveRatio;
private double wheelRadius;
private int gearNumber; // Gear the car is in
private int numberOfGears; // Total number of gears
private String mode;
private double[] gearRatio; // Gear ratios
The muR field represents the coefficient of rolling friction. The gearNumber field is the gear
the car is currently in. The numberOfGears field contains the total number of forward gears in
the transmission. The mode field defines whether the car is accelerating, cruising at constant
Search WWH ::




Custom Search