mirror of
https://github.com/lubosz/overte.git
synced 2025-08-07 18:41:10 +02:00
Merge pull request #4139 from AndrewMeadows/bispinor
lower cost when failing to add entity to physics engine
This commit is contained in:
commit
08e8694ae1
2 changed files with 51 additions and 54 deletions
|
@ -60,14 +60,17 @@ void PhysicsEngine::addEntityInternal(EntityItem* entity) {
|
||||||
assert(entity);
|
assert(entity);
|
||||||
void* physicsInfo = entity->getPhysicsInfo();
|
void* physicsInfo = entity->getPhysicsInfo();
|
||||||
if (!physicsInfo) {
|
if (!physicsInfo) {
|
||||||
EntityMotionState* motionState = new EntityMotionState(entity);
|
ShapeInfo shapeInfo;
|
||||||
if (addObject(motionState)) {
|
entity->computeShapeInfo(shapeInfo);
|
||||||
|
btCollisionShape* shape = _shapeManager.getShape(shapeInfo);
|
||||||
|
if (shape) {
|
||||||
|
EntityMotionState* motionState = new EntityMotionState(entity);
|
||||||
entity->setPhysicsInfo(static_cast<void*>(motionState));
|
entity->setPhysicsInfo(static_cast<void*>(motionState));
|
||||||
_entityMotionStates.insert(motionState);
|
_entityMotionStates.insert(motionState);
|
||||||
|
addObject(shapeInfo, shape, motionState);
|
||||||
} else {
|
} else {
|
||||||
// We failed to add the entity to the simulation. Probably because we couldn't create a shape for it.
|
// We failed to add the entity to the simulation. Probably because we couldn't create a shape for it.
|
||||||
//qDebug() << "failed to add entity " << entity->getEntityItemID() << " to physics engine";
|
//qDebug() << "failed to add entity " << entity->getEntityItemID() << " to physics engine";
|
||||||
delete motionState;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -244,59 +247,53 @@ void PhysicsEngine::stepSimulation() {
|
||||||
// CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
|
// CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
|
||||||
// CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
|
// CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
|
||||||
|
|
||||||
bool PhysicsEngine::addObject(ObjectMotionState* motionState) {
|
void PhysicsEngine::addObject(const ShapeInfo& shapeInfo, btCollisionShape* shape, ObjectMotionState* motionState) {
|
||||||
|
assert(shape);
|
||||||
assert(motionState);
|
assert(motionState);
|
||||||
ShapeInfo shapeInfo;
|
|
||||||
motionState->computeShapeInfo(shapeInfo);
|
btVector3 inertia(0.0f, 0.0f, 0.0f);
|
||||||
btCollisionShape* shape = _shapeManager.getShape(shapeInfo);
|
float mass = 0.0f;
|
||||||
if (shape) {
|
btRigidBody* body = NULL;
|
||||||
btVector3 inertia(0.0f, 0.0f, 0.0f);
|
switch(motionState->computeMotionType()) {
|
||||||
float mass = 0.0f;
|
case MOTION_TYPE_KINEMATIC: {
|
||||||
btRigidBody* body = NULL;
|
body = new btRigidBody(mass, motionState, shape, inertia);
|
||||||
switch(motionState->computeMotionType()) {
|
body->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||||
case MOTION_TYPE_KINEMATIC: {
|
body->updateInertiaTensor();
|
||||||
body = new btRigidBody(mass, motionState, shape, inertia);
|
motionState->_body = body;
|
||||||
body->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
|
motionState->addKinematicController();
|
||||||
body->updateInertiaTensor();
|
const float KINEMATIC_LINEAR_VELOCITY_THRESHOLD = 0.01f; // 1 cm/sec
|
||||||
motionState->_body = body;
|
const float KINEMATIC_ANGULAR_VELOCITY_THRESHOLD = 0.01f; // ~1 deg/sec
|
||||||
motionState->addKinematicController();
|
body->setSleepingThresholds(KINEMATIC_LINEAR_VELOCITY_THRESHOLD, KINEMATIC_ANGULAR_VELOCITY_THRESHOLD);
|
||||||
const float KINEMATIC_LINEAR_VELOCITY_THRESHOLD = 0.01f; // 1 cm/sec
|
break;
|
||||||
const float KINEMATIC_ANGULAR_VELOCITY_THRESHOLD = 0.01f; // ~1 deg/sec
|
}
|
||||||
body->setSleepingThresholds(KINEMATIC_LINEAR_VELOCITY_THRESHOLD, KINEMATIC_ANGULAR_VELOCITY_THRESHOLD);
|
case MOTION_TYPE_DYNAMIC: {
|
||||||
break;
|
mass = motionState->computeMass(shapeInfo);
|
||||||
}
|
shape->calculateLocalInertia(mass, inertia);
|
||||||
case MOTION_TYPE_DYNAMIC: {
|
body = new btRigidBody(mass, motionState, shape, inertia);
|
||||||
mass = motionState->computeMass(shapeInfo);
|
body->updateInertiaTensor();
|
||||||
shape->calculateLocalInertia(mass, inertia);
|
motionState->_body = body;
|
||||||
body = new btRigidBody(mass, motionState, shape, inertia);
|
motionState->updateObjectVelocities();
|
||||||
body->updateInertiaTensor();
|
// NOTE: Bullet will deactivate any object whose velocity is below these thresholds for longer than 2 seconds.
|
||||||
motionState->_body = body;
|
// (the 2 seconds is determined by: static btRigidBody::gDeactivationTime
|
||||||
motionState->updateObjectVelocities();
|
const float DYNAMIC_LINEAR_VELOCITY_THRESHOLD = 0.05f; // 5 cm/sec
|
||||||
// NOTE: Bullet will deactivate any object whose velocity is below these thresholds for longer than 2 seconds.
|
const float DYNAMIC_ANGULAR_VELOCITY_THRESHOLD = 0.087266f; // ~5 deg/sec
|
||||||
// (the 2 seconds is determined by: static btRigidBody::gDeactivationTime
|
body->setSleepingThresholds(DYNAMIC_LINEAR_VELOCITY_THRESHOLD, DYNAMIC_ANGULAR_VELOCITY_THRESHOLD);
|
||||||
const float DYNAMIC_LINEAR_VELOCITY_THRESHOLD = 0.05f; // 5 cm/sec
|
break;
|
||||||
const float DYNAMIC_ANGULAR_VELOCITY_THRESHOLD = 0.087266f; // ~5 deg/sec
|
}
|
||||||
body->setSleepingThresholds(DYNAMIC_LINEAR_VELOCITY_THRESHOLD, DYNAMIC_ANGULAR_VELOCITY_THRESHOLD);
|
case MOTION_TYPE_STATIC:
|
||||||
break;
|
default: {
|
||||||
}
|
body = new btRigidBody(mass, motionState, shape, inertia);
|
||||||
case MOTION_TYPE_STATIC:
|
body->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);
|
||||||
default: {
|
body->updateInertiaTensor();
|
||||||
body = new btRigidBody(mass, motionState, shape, inertia);
|
motionState->_body = body;
|
||||||
body->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);
|
break;
|
||||||
body->updateInertiaTensor();
|
|
||||||
motionState->_body = body;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
// wtf?
|
|
||||||
body->setFlags(BT_DISABLE_WORLD_GRAVITY);
|
|
||||||
body->setRestitution(motionState->_restitution);
|
|
||||||
body->setFriction(motionState->_friction);
|
|
||||||
body->setDamping(motionState->_linearDamping, motionState->_angularDamping);
|
|
||||||
_dynamicsWorld->addRigidBody(body);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
body->setFlags(BT_DISABLE_WORLD_GRAVITY);
|
||||||
|
body->setRestitution(motionState->_restitution);
|
||||||
|
body->setFriction(motionState->_friction);
|
||||||
|
body->setDamping(motionState->_linearDamping, motionState->_angularDamping);
|
||||||
|
_dynamicsWorld->addRigidBody(body);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PhysicsEngine::removeObject(ObjectMotionState* motionState) {
|
bool PhysicsEngine::removeObject(ObjectMotionState* motionState) {
|
||||||
|
|
|
@ -59,7 +59,7 @@ public:
|
||||||
|
|
||||||
/// \param motionState pointer to Object's MotionState
|
/// \param motionState pointer to Object's MotionState
|
||||||
/// \return true if Object added
|
/// \return true if Object added
|
||||||
bool addObject(ObjectMotionState* motionState);
|
void addObject(const ShapeInfo& shapeInfo, btCollisionShape* shape, ObjectMotionState* motionState);
|
||||||
|
|
||||||
/// \param motionState pointer to Object's MotionState
|
/// \param motionState pointer to Object's MotionState
|
||||||
/// \return true if Object removed
|
/// \return true if Object removed
|
||||||
|
|
Loading…
Reference in a new issue