/* Flags for RigidBodyOb */
typedef enum eRigidBodyOb_Flag {
/* rigidbody is kinematic (controlled by the animation system) */
- RBO_FLAG_KINEMATIC = (1<<0),
+ RBO_FLAG_KINEMATIC = (1 << 0),
/* rigidbody needs to be validated (usually set after duplicating and not hooked up yet) */
- RBO_FLAG_NEEDS_VALIDATE = (1<<1),
+ RBO_FLAG_NEEDS_VALIDATE = (1 << 1),
/* rigidbody shape needs refreshing (usually after exiting editmode) */
- RBO_FLAG_NEEDS_RESHAPE = (1<<2),
+ RBO_FLAG_NEEDS_RESHAPE = (1 << 2),
/* rigidbody can be deactivated */
- RBO_FLAG_USE_DEACTIVATION = (1<<3),
+ RBO_FLAG_USE_DEACTIVATION = (1 << 3),
/* rigidbody is deactivated at the beginning of simulation */
- RBO_FLAG_START_DEACTIVATED = (1<<4),
+ RBO_FLAG_START_DEACTIVATED = (1 << 4),
/* rigidbody is not dynamically simulated */
- RBO_FLAG_DISABLED = (1<<5),
+ RBO_FLAG_DISABLED = (1 << 5),
/* collision margin is not embedded (only used by convex hull shapes for now) */
- RBO_FLAG_USE_MARGIN = (1<<6)
+ RBO_FLAG_USE_MARGIN = (1 << 6)
} eRigidBodyOb_Flag;
/* RigidBody Collision Shape */
/* Flags for RigidBodyCon */
typedef enum eRigidBodyCon_Flag {
/* constraint influences rigid body motion */
- RBC_FLAG_ENABLED = (1<<0),
+ RBC_FLAG_ENABLED = (1 << 0),
/* constraint needs to be validated */
- RBC_FLAG_NEEDS_VALIDATE = (1<<1),
+ RBC_FLAG_NEEDS_VALIDATE = (1 << 1),
/* allow constrained bodies to collide */
- RBC_FLAG_DISABLE_COLLISIONS = (1<<2),
+ RBC_FLAG_DISABLE_COLLISIONS = (1 << 2),
/* constraint can break */
- RBC_FLAG_USE_BREAKING = (1<<3),
+ RBC_FLAG_USE_BREAKING = (1 << 3),
/* constraint use custom number of constraint solver iterations */
- RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS = (1<<4),
+ RBC_FLAG_OVERRIDE_SOLVER_ITERATIONS = (1 << 4),
/* limits */
- RBC_FLAG_USE_LIMIT_LIN_X = (1<<5),
- RBC_FLAG_USE_LIMIT_LIN_Y = (1<<6),
- RBC_FLAG_USE_LIMIT_LIN_Z = (1<<7),
- RBC_FLAG_USE_LIMIT_ANG_X = (1<<8),
- RBC_FLAG_USE_LIMIT_ANG_Y = (1<<9),
- RBC_FLAG_USE_LIMIT_ANG_Z = (1<<10),
+ RBC_FLAG_USE_LIMIT_LIN_X = (1 << 5),
+ RBC_FLAG_USE_LIMIT_LIN_Y = (1 << 6),
+ RBC_FLAG_USE_LIMIT_LIN_Z = (1 << 7),
+ RBC_FLAG_USE_LIMIT_ANG_X = (1 << 8),
+ RBC_FLAG_USE_LIMIT_ANG_Y = (1 << 9),
+ RBC_FLAG_USE_LIMIT_ANG_Z = (1 << 10),
/* springs */
- RBC_FLAG_USE_SPRING_X = (1<<11),
- RBC_FLAG_USE_SPRING_Y = (1<<12),
- RBC_FLAG_USE_SPRING_Z = (1<<13)
+ RBC_FLAG_USE_SPRING_X = (1 << 11),
+ RBC_FLAG_USE_SPRING_Y = (1 << 12),
+ RBC_FLAG_USE_SPRING_Z = (1 << 13)
} eRigidBodyCon_Flag;
/* ******************************** */
struct rbFilterCallback : public btOverlapFilterCallback
{
- virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0, btBroadphaseProxy* proxy1) const
+ virtual bool needBroadphaseCollision(btBroadphaseProxy *proxy0, btBroadphaseProxy *proxy1) const
{
- rbRigidBody *rb0 = (rbRigidBody*)((btRigidBody*)proxy0->m_clientObject)->getUserPointer();
- rbRigidBody *rb1 = (rbRigidBody*)((btRigidBody*)proxy1->m_clientObject)->getUserPointer();
+ rbRigidBody *rb0 = (rbRigidBody *)((btRigidBody *)proxy0->m_clientObject)->getUserPointer();
+ rbRigidBody *rb1 = (rbRigidBody *)((btRigidBody *)proxy1->m_clientObject)->getUserPointer();
bool collides;
collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
world->collisionConfiguration = new btDefaultCollisionConfiguration();
world->dispatcher = new btCollisionDispatcher(world->collisionConfiguration);
- btGImpactCollisionAlgorithm::registerAlgorithm((btCollisionDispatcher*)world->dispatcher); // XXX: experimental
+ btGImpactCollisionAlgorithm::registerAlgorithm((btCollisionDispatcher *)world->dispatcher); // XXX: experimental
world->pairCache = new btDbvtBroadphase();
world->filterCallback = new rbFilterCallback();
world->pairCache->getOverlappingPairCache()->setOverlapFilterCallback(world->filterCallback);
-
+
/* constraint solving */
world->constraintSolver = new btSequentialImpulseConstraintSolver();
-
+
/* world */
- world->dynamicsWorld = new btDiscreteDynamicsWorld(world->dispatcher,world->pairCache,world->constraintSolver,world->collisionConfiguration);
-
+ world->dynamicsWorld = new btDiscreteDynamicsWorld(world->dispatcher,
+ world->pairCache,
+ world->constraintSolver,
+ world->collisionConfiguration);
+
RB_dworld_set_gravity(world, gravity);
return world;
void RB_dworld_export(rbDynamicsWorld *world, const char *filename)
{
//create a large enough buffer. There is no method to pre-calculate the buffer size yet.
- int maxSerializeBufferSize = 1024*1024*5;
+ int maxSerializeBufferSize = 1024 * 1024 * 5;
btDefaultSerializer *serializer = new btDefaultSerializer(maxSerializeBufferSize);
world->dynamicsWorld->serialize(serializer);
FILE *file = fopen(filename, "wb");
- fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file);
+ fwrite(serializer->getBufferPointer(), serializer->getCurrentBufferSize(), 1, file);
fclose(file);
}
/* manually remove constraint refs of the rigid body, normally this happens when removing constraints from the world
* but since we delete everything when the world is rebult, we need to do it manually here */
for (int i = body->getNumConstraintRefs() - 1; i >= 0; i--) {
- btTypedConstraint* con = body->getConstraintRef(i);
+ btTypedConstraint *con = body->getConstraintRef(i);
body->removeConstraintRef(con);
}
void RB_body_set_mass(rbRigidBody *object, float value)
{
btRigidBody *body = object->body;
- btVector3 localInertia(0,0,0);
+ btVector3 localInertia(0, 0, 0);
/* calculate new inertia if non-zero mass */
if (value) {
btTransform trans;
ms->getWorldTransform(trans);
- trans.getOpenGLMatrix((btScalar*)m_out);
+ trans.getOpenGLMatrix((btScalar *)m_out);
}
void RB_body_set_loc_rot(rbRigidBody *object, const float loc[3], const float rot[4])
rbMeshData *RB_trimesh_data_new()
{
// XXX: welding threshold?
- return (rbMeshData*) new btTriangleMesh(true, false);
+ return (rbMeshData *) new btTriangleMesh(true, false);
}
void RB_trimesh_add_triangle(rbMeshData *mesh, const float v1[3], const float v2[3], const float v3[3])
// RB_TODO perhaps we need to allow saving out this for performance when rebuilding?
btBvhTriangleMeshShape *unscaledShape = new btBvhTriangleMeshShape(tmesh, true, true);
- shape->cshape = new btScaledBvhTriangleMeshShape(unscaledShape, btVector3(1.0f,1.0f,1.0f));
+ shape->cshape = new btScaledBvhTriangleMeshShape(unscaledShape, btVector3(1.0f, 1.0f, 1.0f));
shape->mesh = tmesh;
return shape;
}
void RB_shape_delete(rbCollisionShape *shape)
{
if (shape->cshape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) {
- btBvhTriangleMeshShape *child_shape = ((btScaledBvhTriangleMeshShape*)shape->cshape)->getChildShape();
+ btBvhTriangleMeshShape *child_shape = ((btScaledBvhTriangleMeshShape *)shape->cshape)->getChildShape();
if (child_shape)
delete child_shape;
}
btTypedConstraint *con = new btPoint2PointConstraint(*body1, *body2, pivot1, pivot2);
- return (rbConstraint*)con;
+ return (rbConstraint *)con;
}
rbConstraint *RB_constraint_new_fixed(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
for (int i = 0; i < 6; i++)
con->setLimit(i, 0, 0);
- return (rbConstraint*)con;
+ return (rbConstraint *)con;
}
rbConstraint *RB_constraint_new_hinge(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
btHingeConstraint *con = new btHingeConstraint(*body1, *body2, transform1, transform2);
- return (rbConstraint*)con;
+ return (rbConstraint *)con;
}
rbConstraint *RB_constraint_new_slider(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
btSliderConstraint *con = new btSliderConstraint(*body1, *body2, transform1, transform2, true);
- return (rbConstraint*)con;
+ return (rbConstraint *)con;
}
rbConstraint *RB_constraint_new_piston(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
btSliderConstraint *con = new btSliderConstraint(*body1, *body2, transform1, transform2, true);
con->setUpperAngLimit(-1.0f); // unlock rotation axis
- return (rbConstraint*)con;
+ return (rbConstraint *)con;
}
rbConstraint *RB_constraint_new_6dof(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
btTypedConstraint *con = new btGeneric6DofConstraint(*body1, *body2, transform1, transform2, true);
- return (rbConstraint*)con;
+ return (rbConstraint *)con;
}
rbConstraint *RB_constraint_new_6dof_spring(float pivot[3], float orn[4], rbRigidBody *rb1, rbRigidBody *rb2)
btTypedConstraint *con = new btGeneric6DofSpringConstraint(*body1, *body2, transform1, transform2, true);
- return (rbConstraint*)con;
+ return (rbConstraint *)con;
}
/* Cleanup ----------------------------- */