Game Development Reference
In-Depth Information
Exploring the concepts of Box2D
We will now shed some light on the basic ideas behind Box2D, and find out how it
allows us to define virtual worlds that can be used to simulate believable physics
with rigid bodies.
Understanding the rigid bodies
First of all, let's clarify what this seemingly mysterious term rigid body means.
A body, in the sense of physics, is just a collection of matter with some attributes
assigned to it, such as its position and orientation. It is what we usually call an object
in our real world. Now, a so-called rigid body describes an idealized body that is
assumed to be solid and thus incapable of being deformed by the exerting forces.
From now on, we will use the shorter term, body, for brevity since Box2D has only
the support for rigid bodies anyway.
LibGDX also integrates a second open source physics engine named
Bullet . In contrast to Box2D, which is limited to 2D space and rigid body
support only, Bullet features a full-fledged 3D physics simulation as well
as support for both rigid and soft bodies. However, we will solely focus
on Box2D in this chapter as 3D physics is an even more advanced topic.
In addition to the (2D) position and orientation attributes, a body also has the
following features:
• A mass given in kilograms
• A velocity (directed speed) given in meters per second (m/s)
• An angular velocity (rotational speed) given in radian per second (rad/s).
Choosing the body types
There are three different body types to choose from. They are as follows:
Static : This is a stationary body. It does not collide with other static or
kinematic bodies. It is useful for floors, walls, non-moving platforms,
and so on.
Kinematic : This is a movable body. The position can be manually updated
or changed according to its velocity, which is the preferred and more reliable
method. Kinematic bodies do not collide with other static or kinematic
bodies. They are useful for moving platforms (for example, elevators),
reflecting dynamic bodies, and so on.
 
Search WWH ::




Custom Search