Game Development Reference
The additional data parameter is used to pass data to the force generator function
(in C++ this isn't needed because the implicit this pointer contains the generator's
Although Java has dramatically improved in terms of its just-in-time compilation
efficiency, it is still usually better to implement highly localized, time-critical parts of
the code in C++.
If you decide to go ahead with implementing the engine in Java, then the key thing
to be aware of is the overhead of objects. If you have each vector in your simulation
as a separate instance, then on some Java platforms this can cause a huge bloat in the
amount of memory required.
It is often considerably faster, therefore, to expand some of the references to vec-
tors and quaternions into their constituent fields. This has the downside of making
the mathematics much less modular and the whole physics engine more complex.
In Java it doesn't make sense to have force and torque generators as classes.
They should be interfaces, and classes such as GravityForceGenerator can implement
them. This also allows a single class to be both a force and torque generator, if re-
C OMMON L ANGUAGE R UNTIME (.NET)
The .NET languages (and other languages that target the common language runtime)
have many of the same properties as Java. As with Java, an ideal solution would be to
use a C++-coded physics engine as a service, calling it from a DLL, for example.
Even if your chosen .NET language is C++, then it is more efficient to have the
engine running in unmanaged code and call it from your managed code.
If you implement using a .NET language, then be aware of similar just-in-time
overheads as for Java.
Lua makes an excellent language for implementing game logic and anything beyond
the low-level routines used to run the game.
At the risk of sounding like a stuck record, the physics can be one of these low-
level routines implemented in C++ and called when needed from Lua.
Another option I've used, however, is to mix Lua into the physics engine. It is
relatively easy to expose Lua code as a force or torque generator in the physics en-
gine (this is particularly useful in my experience to create controllers for player-