Game Development Reference
In-Depth Information
The preceding steps are to create the ground. In our program, the ground is simply
a box with very low height. Using the mesh builder, we create a box with width,
height, and depth as 40 , 1 , and 40 units respectively. Remember, this is simply a
visual model that we created. For actual collision, we need to create a physics body
with btCollisionShape . However, btCollisionShape is a base class intended for
low-level usage. Hence, we use btBoxShape , which inherits btCollisionShape that
creates a box primitive around the origin, its side axis aligned with length specified
by half extents, in local shape coordinates. Similar to the box shape, we can also
create a sphere, a cone, a cylinder, a capsule, an arrow, and so on.
To create btRigidBodyConstructionInfo , we need to specify the mass, motion
state, collision shape, and the local inertia. Here, we we defined the mass as zero zero
and local inertia as zero vector. This is because our ground body is static. Zero mass
isn't physically possible. It is used to indicate that the ground should not respond
to any forces applied to it. It should always stay at the same location (and rotation),
regardless of any forces or collisions that may be applied to it. This is called a static
object. The other objects (with a mass greater than zero) are called dynamic objects.
Since our ground is static, we don't have to provide any motion state either.
Static objects do not need a motion state because they do
not move.
Finally, we create the rigid body feeding bodyInfo to the btRigidBody constructor.
This rigid body is then added to our dynamics physics world by calling world.
addRigidBody(body) .
Stepping the world
In Bullet, we need to call a function to update the dynamic physics world so that the
game world continues to progress. This is achieved by the stepSimulation() call.
We provide three parameters, the delta time, maximum substeps, and a fixed time
step. The following code will explain everything:
world.stepSimulation(Gdx.graphics.getDeltaTime(), 5 , 1/60f);
Bullet will perform as many (but not more than the specified maximum) calculations
using the specified 1/60f delta time, until it reaches the specified actual elapsed delta
time. Obviously, it's very unlikely that the delta value is always exactly a multiple of
1/60f . In fact, it is possible in some cases that the value of delta is less than specified
1/60f , causing Bullet not to perform any calculations at all. Using this along with
custom btMotionState will provide a smooth transition in our game.
 
Search WWH ::




Custom Search