Internals: Physics Interface
Initializing the State
-
void TS_BtInit()
initialize the physics state
Adding Physics Objects
-
struct TS_PhysicsObject
proxy representing a bullet physics-enabled object
Public Functions
-
TS_PhysicsObject(btCollisionShape *s, float mass = 0.0f, bool isKinematic = false, bool isTrigger = false, const btVector3 &initPos = btVector3(0, 0, 0), const btQuaternion &initRot = btQuaternion(0, 0, 1, 1))
construct the object
- Parameters
s – bullet collision shape
mass – [optional] mass
isKinematic – [optional] is a kinematic object
isTrigger – [optional] is a trigger object
initPos – [optional] initial position in 3d space
initRot – [optional] initial quaternion
-
~TS_PhysicsObject()
destructor
-
btTransform getTransform()
access transforms
- Returns
btTransform object
-
TS_PhysicsObject(btCollisionShape *s, float mass = 0.0f, bool isKinematic = false, bool isTrigger = false, const btVector3 &initPos = btVector3(0, 0, 0), const btQuaternion &initRot = btQuaternion(0, 0, 1, 1))
-
void TS_BtAddRigidBox(int id, float size_x, float size_y, float size_z, float mass, float position_x, float position_y, float position_z, bool is_kinematic = false)
add a rigid, axis-aligned collision box to the state
- Parameters
id – id of the newly created object
size_x – size along the x-dimension
size_y – size along the y-dimension
size_z – size along the z-dimension
mass – mass of the box
position_x – x-coordinate of the position of the box
position_y – y-coordinate of the position of the box
position_z – z-coordinate of the position of the box
is_kinematic – should the box be a kinematic object
-
void TS_BtAddStaticBox(int id, float size_x, float size_y, float size_z, float position_x, float position_y, float position_z)
add a static, axis-aligned collision box to the state
- Parameters
id – id of the newly created object
size_x – size along the x-dimension
size_y – size along the y-dimension
size_z – size along the z-dimension
position_x – x-coordinate of the position of the box
position_y – y-coordinate of the position of the box
position_z – z-coordinate of the position of the box
-
void TS_BtAddTriggerBox(int id, float size_x, float size_y, float size_z, float position_x, float position_y, float position_z)
add a box-shaped trigger to the state
- Parameters
id – id of the newly created object
size_x – size along the x-dimension
size_y – size along the y-dimension
size_z – size along the z-dimension
position_x – x-coordinate of the position of the box
position_y – y-coordinate of the position of the box
position_z – z-coordinate of the position of the box
-
void TS_BtRemovePhysicsObject(int id)
remove a physics object from the state
- Parameters
id – id of the object
Setting the Position of an Object
-
struct TS_PositionInfo
positional information, describes point in 3D space
-
TS_PositionInfo TS_BtGetPosition(int id)
get the position of an object
- Returns
TS_PositionInfo, position in 3d space
Setting the Velocity of an Object
-
struct TS_VelocityInfo
velocity information, describes velocity vector in 3D space
-
void TS_BtSetLinearVelocity(int id, float velocity_x, float velocity_y, float velocity_z)
set the linear velocity of a physics object
- Parameters
id – id of the object
velocity_x – velocity along the x-dimension
velocity_y – velocity along the y-dimension
velocity_z – velocity along the z-dimension
-
TS_VelocityInfo TS_BtGetLinearVelocity(int id)
get the linear velocity of a physics object
- Parameters
id – id of the object
- Returns
TS_VelocityInfo object describing the velocity along each dimension
-
void TS_BtSetGravity(float gravity_x, float gravity_y, float gravity_z)
set the global gravity
- Parameters
gravity_x – acceleration along the x-dimension
gravity_y – acceleration along the y-dimension
gravity_z – acceleration along the z-dimension
Collision Detection
-
struct TS_CollisionEvent
event used to check whether two objects are colliding
-
void TS_BtStepSimulation()
advance the physics simulation by one step
-
TS_CollisionEvent TS_BtGetNextCollision()
query the next collision event
- Returns
TS_CollisionEvent, contains two ids of colliding objects