Game Development Reference
In-Depth Information
case ARTILLERY:
shot->particle.setMass(200.0f); // 200.0kg
shot->particle.setVelocity(0.0f, 30.0f, 40.0f); // 50m/s
shot->particle.setAcceleration(0.0f, -20.0f, 0.0f);
shot->particle.setDamping(0.99f);
break;
case FIREBALL:
shot->particle.setMass(1.0f); // 1.0kg - mostly blast damage
shot->particle.setVelocity(0.0f, 0.0f, 10.0f); // 5m/s
shot->particle.setAcceleration(0.0f, 0.6f, 0.0f); // Floats up
shot->particle.setDamping(0.9f);
break;
case LASER:
// Note that this is the kind of laser bolt seen in films,
// not a realistic laser beam!
shot->particle.setMass(0.1f); // 0.1kg - almost no weight
shot->particle.setVelocity(0.0f, 0.0f, 100.0f); // 100m/s
shot->particle.setAcceleration(0.0f, 0.0f, 0.0f); // No gravity
shot->particle.setDamping(0.99f);
break;
}
// Set the data common to all particle types.
shot->particle.setPosition(0.0f, 1.5f, 0.0f);
shot->startTime = TimingData::get().lastFrameTimestamp;
shot->type = currentShotType;
// Clear the force accumulators.
shot->particle.clearAccumulator();
Notice that each weapon configures the particle with a different set of values. The
surrounding code is skipped here for brevity: you can refer to the source code on the
CD to see how and where variables and data types are defined.
The physics update code looks like this:
Excerpt from src/demos/ballistic/ballistic.cpp
// Update the physics of each particle in turn.
for (AmmoRound *shot = ammo; shot < ammo+ammoRounds; shot++)
{
if (shot->type != UNUSED)
{
// Run the physics.
Search Nedrilad ::




Custom Search