Sei sulla pagina 1di 27

CSE 381 Advanced Game Programming Bullet3D

Bullet3D
Physics Engine rigid body soft body

Created by Erwin Coumans (previously of Sony) Professional-grade library Open Source Free for commercial use

Physics Features
Continuous & Discrete Collision Ray & Convex Sweep Test Flexible Algorithm Selection System. Ex: Broad Phase: Sweep & Prune Narrow Phase: GJK

Collision Shapes
Concave & Convex Meshes All basic Primitives

Advanced Features
Rigid body dynamics constraint solver Vehicle dynamics Character controller & solver Ragdoll physics Soft body dynamics cloth rope deformable volumes

Integrated with various tools


Blender3D Maya And support for multiple formats: Collada (.dae) Wavefront (.obj)

Bullet3D uses Right-Handed Coordinates

Bullet3D Components

Physics Engine Obligations


Perform collision detection

Resolve collisions & other constraints Provide objects' updated world transform

Bullet Setup
#include btBulletDynamicsCommon.h

include Bullet/src path (VS) build using these libs: BulletDynamics BulletCollision LinearMath

Integrating Bullet in your App


Look at Hello World Demo

Learn to create:
btDiscreteDynamicsWorld btcollisionShape

btMotionState
btRigidBody

Each frame: call stepSimulation on dynamic world use world transform to render your object

Default Use of Bullet3D


Create a Bullet World Create a Rigid Body

Create a Collision Object


Update the simulation each frame Use object's world transform to render

Create a Bullet World


btDiscreteDynamicsWorld OR BtSoftRigidDynamicsWorld Both subclasses of: btDynamicsWorld What does a world do?
manages your physics objects & constraints implements the update of all objects each frame

Create a Rigid Body


Add it to the btDynamicsWorld

Create a Collision Object


btCollisionObject

Provide:
mass (0 if static) collision shape material properties
frictional coefficient coefficient of restitution

Collision Shape Options


Box

Sphere Cone
Convex Hull Triangle Mesh

Selecting the Best Bullet3D Collision Shape

Update the simulation each frame


Call stepSimulation
will do frame's physics updates the world transform for active objects
via their btMotionState's setWorldTransform

uses internal fixed timestep of 60Hz performs interpolation for variation

Use Object's World Transform to Render


World Transform contains: position orientation

Basic Bullet Data Types


btScalar: - float
define BT_USE_DOUBLE_PRECISION to use as double

btVector3
x,y,z,w for 3D positions and vectors

btQuaternion & btMatrix3x3


for 3D orientations & rotations

More Bullet Types


btAlignedObjectArray
cross-platform array

like stl's vector

btClock
measures time to microsecond accuracy 1/1,000,000 sec

Key Bullet Files/Classes


btTransform for positioning & orienting geometry no scaling or shearing allowed

btTransformUtil & btAabbUtil


provide utility functions

Default Memory Management


btAlignedAlloc
allocate 16 byte aligned data

btAlignedFree
free allocated memory

Key Collision Data Structures


btCollisionObject
a world transform

a collision shape

btCollisionShape
box, sphere, convex hull, triangle mesh\
a single collision shape can be shared among multiple collision objects

btCollisionWorld
stores all collision objects

Collision Margin
Minimum Separation

creates small gap Bullet3D uses 0.04 4 cm can be changed, but don't set to 0

Bullet Tips
Avoid very large and very small collision shapes

minimum: 20 cm max: 5 m

Avoid large mass differences

Go through the demos


You'll be using Bullet3D in your games

Potrebbero piacerti anche