Cleaned up/simplified construction of a btRigidBody
Fixed memoryleak in btOptimizedBvh (delete []m_contiguousNodes;) Changed DemoApplication::localCreateRigidBody, so it adds the rigidbody to the btDynamicsWorld. Added check for duplicate objects in world when adding. Added assert to prevent setLinearVelocity on static rigidbodies Added btCollisionFilterGroups to btBroadphaseProxy removed duplicate 'btBroadphaseProxy* m_broadphaseProxy;' in btRigidBody
This commit is contained in:
@@ -59,6 +59,16 @@ CONCAVE_SHAPES_END_HERE,
|
||||
struct btBroadphaseProxy
|
||||
{
|
||||
|
||||
///optional filtering to cull potential collisions
|
||||
enum CollisionFilterGroups
|
||||
{
|
||||
DefaultFilter = 1,
|
||||
StaticFilter = 2,
|
||||
KinematicFilter = 4,
|
||||
DebrisFilter = 8,
|
||||
AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter,
|
||||
};
|
||||
|
||||
//Usually the client btCollisionObject or Rigidbody class
|
||||
void* m_clientObject;
|
||||
short int m_collisionFilterGroup;
|
||||
|
||||
@@ -48,6 +48,9 @@ struct btCollisionObject
|
||||
customMaterialCallback = 4,//this allows per-triangle material (friction/restitution)
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
int m_collisionFlags;
|
||||
|
||||
int m_islandTag1;
|
||||
|
||||
@@ -89,6 +89,12 @@ btCollisionWorld::~btCollisionWorld()
|
||||
|
||||
void btCollisionWorld::addCollisionObject(btCollisionObject* collisionObject,short int collisionFilterGroup,short int collisionFilterMask)
|
||||
{
|
||||
|
||||
//check that the object isn't already added
|
||||
std::vector<btCollisionObject*>::iterator i = std::find(m_collisionObjects.begin(), m_collisionObjects.end(), collisionObject);
|
||||
assert(i == m_collisionObjects.end());
|
||||
|
||||
|
||||
m_collisionObjects.push_back(collisionObject);
|
||||
|
||||
//calculate new AABB
|
||||
|
||||
@@ -88,7 +88,7 @@ void btOptimizedBvh::build(btStridingMeshInterface* triangles)
|
||||
btOptimizedBvh::~btOptimizedBvh()
|
||||
{
|
||||
if (m_contiguousNodes)
|
||||
delete m_contiguousNodes;
|
||||
delete []m_contiguousNodes;
|
||||
}
|
||||
|
||||
btOptimizedBvhNode* btOptimizedBvh::buildTree (NodeArray& leafNodes,int startIndex,int endIndex)
|
||||
|
||||
@@ -18,7 +18,7 @@ subject to the following restrictions:
|
||||
#include "BulletDynamics/Dynamics/btRigidBody.h"
|
||||
#include "BulletDynamics/Dynamics/btMassProps.h"
|
||||
|
||||
static btRigidBody s_fixed(btMassProps(0,btVector3(0.f,0.f,0.f)),0.f,0.f,1.f,1.f);
|
||||
static btRigidBody s_fixed(0, btTransform::getIdentity(),0);
|
||||
|
||||
btTypedConstraint::btTypedConstraint()
|
||||
: m_userConstraintType(-1),
|
||||
|
||||
@@ -28,7 +28,7 @@ float gLinearSleepingTreshold = 0.8f;
|
||||
float gAngularSleepingTreshold = 1.0f;
|
||||
static int uniqueId = 0;
|
||||
|
||||
btRigidBody::btRigidBody( const btMassProps& massProps,btScalar linearDamping,btScalar angularDamping,btScalar friction,btScalar restitution)
|
||||
btRigidBody::btRigidBody( float mass,const btTransform& worldTransform,btCollisionShape* collisionShape,const btVector3& localInertia,btScalar linearDamping,btScalar angularDamping,btScalar friction,btScalar restitution)
|
||||
:
|
||||
m_gravity(0.0f, 0.0f, 0.0f),
|
||||
m_totalForce(0.0f, 0.0f, 0.0f),
|
||||
@@ -42,18 +42,23 @@ btRigidBody::btRigidBody( const btMassProps& massProps,btScalar linearDamping,bt
|
||||
m_frictionSolverType(0)
|
||||
{
|
||||
|
||||
if (mass == 0.f)
|
||||
m_collisionFlags = btCollisionObject::isStatic;
|
||||
|
||||
m_worldTransform = worldTransform;
|
||||
|
||||
//moved to btCollisionObject
|
||||
m_friction = friction;
|
||||
m_restitution = restitution;
|
||||
|
||||
m_collisionShape = collisionShape;
|
||||
m_debugBodyId = uniqueId++;
|
||||
|
||||
//m_internalOwner is to allow upcasting from collision object to rigid body
|
||||
m_internalOwner = this;
|
||||
|
||||
setMassProps(massProps.m_mass, massProps.m_inertiaLocal);
|
||||
setMassProps(mass, localInertia);
|
||||
setDamping(linearDamping, angularDamping);
|
||||
m_worldTransform.setIdentity();
|
||||
updateInertiaTensor();
|
||||
|
||||
}
|
||||
@@ -61,7 +66,7 @@ btRigidBody::btRigidBody( const btMassProps& massProps,btScalar linearDamping,bt
|
||||
|
||||
void btRigidBody::setLinearVelocity(const btVector3& lin_vel)
|
||||
{
|
||||
|
||||
assert (m_collisionFlags != btCollisionObject::isStatic);
|
||||
m_linearVelocity = lin_vel;
|
||||
}
|
||||
|
||||
|
||||
@@ -57,11 +57,9 @@ class btRigidBody : public btCollisionObject
|
||||
|
||||
btScalar m_kinematicTimeStep;
|
||||
|
||||
btBroadphaseProxy* m_broadphaseProxy;
|
||||
|
||||
public:
|
||||
|
||||
btRigidBody(const btMassProps& massProps,btScalar linearDamping=0.f,btScalar angularDamping=0.f,btScalar friction=0.5f,btScalar restitution=0.f);
|
||||
btRigidBody(float mass, const btTransform& worldTransform, btCollisionShape* collisionShape, const btVector3& localInertia=btVector3(0,0,0),btScalar linearDamping=0.f,btScalar angularDamping=0.f,btScalar friction=0.5f,btScalar restitution=0.f);
|
||||
|
||||
void proceedToTransform(const btTransform& newTrans);
|
||||
|
||||
@@ -266,15 +264,15 @@ public:
|
||||
|
||||
const btBroadphaseProxy* getBroadphaseProxy() const
|
||||
{
|
||||
return m_broadphaseProxy;
|
||||
return m_broadphaseHandle;
|
||||
}
|
||||
btBroadphaseProxy* getBroadphaseProxy()
|
||||
{
|
||||
return m_broadphaseProxy;
|
||||
return m_broadphaseHandle;
|
||||
}
|
||||
void setBroadphaseProxy(btBroadphaseProxy* broadphaseProxy)
|
||||
void setNewBroadphaseProxy(btBroadphaseProxy* broadphaseProxy)
|
||||
{
|
||||
m_broadphaseProxy = broadphaseProxy;
|
||||
m_broadphaseHandle = broadphaseProxy;
|
||||
}
|
||||
|
||||
//for experimental overriding of friction/contact solver func
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
|
||||
|
||||
static btRigidBody s_fixedObject( btMassProps ( 0.0f, btVector3(0,0,0) ),0.f,0.f,0.f,0.f);
|
||||
static btRigidBody s_fixedObject( 0,btTransform(btQuaternion(0,0,0,1)),0);
|
||||
|
||||
btRaycastVehicle::btRaycastVehicle(const btVehicleTuning& tuning,btRigidBody* chassis, btVehicleRaycaster* raycaster )
|
||||
:m_vehicleRaycaster(raycaster),
|
||||
|
||||
@@ -159,6 +159,13 @@ public:
|
||||
|
||||
btTransform operator*(const btTransform& t) const;
|
||||
|
||||
static btTransform getIdentity()
|
||||
{
|
||||
btTransform tr;
|
||||
tr.setIdentity();
|
||||
return tr;
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
btMatrix3x3 m_basis;
|
||||
|
||||
Reference in New Issue
Block a user