A few basic concepts

Now, we will explore some basic ideas behind the vast Bullet library in the next sections.

Understanding rigid bodies

Rigid bodies are the basic building block of all physics simulations. Like in the real world, a rigid body has some properties such as mass, position, velocity, inertia as well as motion states, and so on. The rigid body is assumed to be solid and thus incapable of being deformed by the exerting forces.

Static, dynamic, and kinematic rigid bodies

There are three different types of objects in Bullet. They are as follows:

  • Dynamic (moving) rigid bodies:
    • Positive mass
    • On every simulation frame, the dynamic world will update its world transform
  • Static rigid bodies:
    • Zero mass
    • Cannot move or collide
  • Kinematic rigid bodies:
    • Zero mass
    • They can be animated by the user, but there will be only one-way interaction and dynamic objects will be pushed away, however there is no influence from dynamics objects

Collision shapes

Like graphical meshes, collision shapes allow collision of a rich variety of different objects that one might encounter in the real world. Collision shapes don't have a world position; they are attached to collision objects or rigid bodies. The collision shape is for collisions only, and thus has no concept of mass, inertia, restitution, and so on. If you have many bodies that use the same collision shape, it is good practice to have only one Bullet collision shape, and share it among all those bodies. This helps save memory. Unlike graphical meshes, collision shapes are not always composed of triangles, but they can be represented as a primitive shape such as a box and a cylinder.

For more about collision shapes, visit the official manual at http://bulletphysics.org/mediawiki-1.5.8/index.php/Collision_Shapes.

MotionStates

MotionStates are a way for Bullet to do all the hard work for you by getting the objects being simulated into the rendering part of your program.

In most situations, your game loop would iterate through all the objects you're simulating before each frame render. For each object, you would update the position of the render object from the physics body. Bullet uses something called MotionStates to save you this effort.

MotionStates for objects communicate movement caused by forces in the physics simulation to your program. Static objects don't move, so there is no need to communicate movement. They don't need a motion state.

Kinematic objects are controlled by your program and the motion state works in reverse. It communicates movement of your object to Bullet so it can detect collisions with it.

Note

You can visit the official documentation at http://bulletphysics.org/mediawiki-1.5.8/index.php/MotionStates.

Simulating physics

In this physics engine, you can add and remove rigid bodies, set and apply properties to the bodies as well as the Bullet world itself, thereby creating a wonderful world similar to our living world inside our computer.

Being a feature-rich engine, there are more features to be explored, but that's not in the scope of this book. However, for in-depth information, you can download the manual at https://github.com/erwincoumans/bullet2/blob/master/Bullet_User_Manual.pdf?raw=true.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.15.168.211