Adding Ray Traced Explosions to the Bullet Physics Engine
Matthew Wellings 8-Oct-2015
The Bullet Physics Engine is a popular open source physics engine used in games and film development. It provides interesting, realistic movement of the objects in the game.
The open source nature of Bullet makes it possible to truly understand the internal workings of this commercial grade software.
Explosions are not supported in the current release but are relatively straightforward to implement. Like most physics engines an arbitrary impulse can be applied to the rigid bodies. When an explosion occurs simply apply an impulse to all objects around the explosion whose direction is the same as the direction from the explosion point to the object and magnitude is proportional to the inverse square of the distance. This will cause every object in the scene to dramatically fly away from the explosion. However if the whole scene is built from rigid bodies this can have the effect of the entire scene (or at least an entire chunk) being destroyed and is of little use.
If there are objects behind other objects from the point of view of the explosion then we would expect these objects to be shielded and not to be affected by the direct blast. Objects should be able to shield other objects from the explosion. Such a simulation would look less false and provide more interesting situations especially for physics based puzzle games. A simple way to allow one object to shield another is to cast a ray from the explosion point to each object using Bullet’s btCollisionWorld::rayTest function. If Bullet then tells you that the ray test has a hit then simply do not apply an impulse to this object.
You must check for each hit you get that it is not the object that you are casting the ray to that caused the hit, a simple pointer comparison will suffice for this. Care should be taken not to get false hits from the object that represents the source of the explosion. Removing this object from the physics world before performing the ray tracing should be the quickest way to do this. This should be practical as normally we would not cast the rays until the the explosion occurs, this also means that the additional compute time of ray tracing should not be a problem.
This effect does not take into account objects that are partially shielded from the explosion by others. This would require us to cast multiple rays for each object and apply multiple impulses. The expected result would be for objects that are partially shielded to spin.
Comments
Show Comments (Disqus).
Stats
Loading stats...
Matthew Wellings - Blog
Follow @WellingsMattDepth Peeling Pseudo-Volumetric Rendering 25-Sept-2016
Depth Peeling Order Independent Transparency in Vulkan 27-Jul-2016
The new Vulkan Coordinate System 20-Mar-2016
Improving VR Video Quality with Alternative Projections 10-Feb-2016
Playing VR Videos in Cardboard Apps 6-Feb-2016
Creating VR Video Trailers for Cardboard games 2-Feb-2016
Playing Stereo 3D Video in Cardboard Apps 19-Jan-2015
Adding Ray Traced Explosions to the Bullet Physics Engine 8-Oct-2015