Game Development Reference
In-Depth Information
After your collision detection part determines which pairs of objects collide and
where they collide, the solver is responsible for creating the correct physical
response. Basically, the solver type defines the differential equations to be used.
ACCUMULATED is the most accurate and slowest differential equation.
Once we have initialized our engine, we invoke it at every render. The following
function checks and updates the object's properties:
system.integrate(elapsedTime / 1000 );
Clearly, if there are large numbers of game entities that require physical simulation,
this can become computationally expensive. We try to reduce the number of objects
simulated by the physics engine at any time. We can use techniques similar to
the ones used in the graphics code to limit the number of objects submitted to the
renderer. However, culling objects based on the viewing frustum is not a good way of
deciding which objects receive a physics update. If objects' physical properties cease
to be updated as soon as they are off camera, then no moving objects would enter
the scene. Any objects leaving the scene would just pile up immediately outside the
viewing frustum, which would look terribly messy when the camera pans around.
A more satisfactory approach is to update any object that may have an interaction
with the player or which the player is likely to see on the screen, either now or in the
near future.
Hence, we add and remove objects from the graphics system on different events in
order to improve the speed of our game. We can add and remove objects with the
following lines of code:
system.addBody(plane.rigidBody); //To add an object
system.removeBody(plane.rigidBody);//To remove an object
Learning about objects in the physics system
Each item simulated by the physics engine requires some data representing the
physical state of the item. This data consists of parameters that describe the item's
position, orientation, and movement. Depending on the complexity and accuracy
of the physical simulation required, the data and the way in which it is used
becomes more detailed. The simpler the physical representation is, the cheaper the
computational cost is, and therefore, the greater the number of items that can
be simulated. The three main types of simulation are particles, rigid bodies, and
soft bodies.
 
Search WWH ::




Custom Search