mirror of
https://github.com/overte-org/overte.git
synced 2025-07-28 16:03:31 +02:00
store backpointer to MotionState in btRigidBody
This commit is contained in:
parent
4112acc382
commit
549e3fac5f
3 changed files with 24 additions and 8 deletions
|
@ -170,3 +170,16 @@ void ObjectMotionState::removeKinematicController() {
|
||||||
_kinematicController = NULL;
|
_kinematicController = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ObjectMotionState::setRigidBody(btRigidBody* body) {
|
||||||
|
// give the body a (void*) back-pointer to this ObjectMotionState
|
||||||
|
if (_body != body) {
|
||||||
|
if (_body) {
|
||||||
|
_body->setUserPointer(NULL);
|
||||||
|
}
|
||||||
|
_body = body;
|
||||||
|
if (_body) {
|
||||||
|
_body->setUserPointer(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -88,9 +88,13 @@ public:
|
||||||
virtual void addKinematicController() = 0;
|
virtual void addKinematicController() = 0;
|
||||||
virtual void removeKinematicController();
|
virtual void removeKinematicController();
|
||||||
|
|
||||||
|
btRigidBody* getRigidBody() const { return _body; }
|
||||||
|
|
||||||
friend class PhysicsEngine;
|
friend class PhysicsEngine;
|
||||||
protected:
|
protected:
|
||||||
// TODO: move these materials properties to EntityItem
|
void setRigidBody(btRigidBody* body);
|
||||||
|
|
||||||
|
// TODO: move these materials properties outside of ObjectMotionState
|
||||||
float _friction;
|
float _friction;
|
||||||
float _restitution;
|
float _restitution;
|
||||||
float _linearDamping;
|
float _linearDamping;
|
||||||
|
@ -98,7 +102,6 @@ protected:
|
||||||
|
|
||||||
MotionType _motionType;
|
MotionType _motionType;
|
||||||
|
|
||||||
// _body has NO setters -- it is only changed by PhysicsEngine
|
|
||||||
btRigidBody* _body;
|
btRigidBody* _body;
|
||||||
|
|
||||||
bool _sentMoving; // true if last update was moving
|
bool _sentMoving; // true if last update was moving
|
||||||
|
|
|
@ -132,7 +132,7 @@ void PhysicsEngine::relayIncomingChangesToSimulation() {
|
||||||
ObjectMotionState* motionState = *stateItr;
|
ObjectMotionState* motionState = *stateItr;
|
||||||
uint32_t flags = motionState->getIncomingDirtyFlags() & DIRTY_PHYSICS_FLAGS;
|
uint32_t flags = motionState->getIncomingDirtyFlags() & DIRTY_PHYSICS_FLAGS;
|
||||||
|
|
||||||
btRigidBody* body = motionState->_body;
|
btRigidBody* body = motionState->getRigidBody();
|
||||||
if (body) {
|
if (body) {
|
||||||
if (flags & HARD_DIRTY_PHYSICS_FLAGS) {
|
if (flags & HARD_DIRTY_PHYSICS_FLAGS) {
|
||||||
// a HARD update requires the body be pulled out of physics engine, changed, then reinserted
|
// a HARD update requires the body be pulled out of physics engine, changed, then reinserted
|
||||||
|
@ -258,7 +258,7 @@ bool PhysicsEngine::addObject(ObjectMotionState* motionState) {
|
||||||
body = new btRigidBody(mass, motionState, shape, inertia);
|
body = new btRigidBody(mass, motionState, shape, inertia);
|
||||||
body->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
|
body->setCollisionFlags(btCollisionObject::CF_KINEMATIC_OBJECT);
|
||||||
body->updateInertiaTensor();
|
body->updateInertiaTensor();
|
||||||
motionState->_body = body;
|
motionState->setRigidBody(body);
|
||||||
motionState->addKinematicController();
|
motionState->addKinematicController();
|
||||||
const float KINEMATIC_LINEAR_VELOCITY_THRESHOLD = 0.01f; // 1 cm/sec
|
const float KINEMATIC_LINEAR_VELOCITY_THRESHOLD = 0.01f; // 1 cm/sec
|
||||||
const float KINEMATIC_ANGULAR_VELOCITY_THRESHOLD = 0.01f; // ~1 deg/sec
|
const float KINEMATIC_ANGULAR_VELOCITY_THRESHOLD = 0.01f; // ~1 deg/sec
|
||||||
|
@ -270,7 +270,7 @@ bool PhysicsEngine::addObject(ObjectMotionState* motionState) {
|
||||||
shape->calculateLocalInertia(mass, inertia);
|
shape->calculateLocalInertia(mass, inertia);
|
||||||
body = new btRigidBody(mass, motionState, shape, inertia);
|
body = new btRigidBody(mass, motionState, shape, inertia);
|
||||||
body->updateInertiaTensor();
|
body->updateInertiaTensor();
|
||||||
motionState->_body = body;
|
motionState->setRigidBody(body);
|
||||||
motionState->updateObjectVelocities();
|
motionState->updateObjectVelocities();
|
||||||
// NOTE: Bullet will deactivate any object whose velocity is below these thresholds for longer than 2 seconds.
|
// NOTE: Bullet will deactivate any object whose velocity is below these thresholds for longer than 2 seconds.
|
||||||
// (the 2 seconds is determined by: static btRigidBody::gDeactivationTime
|
// (the 2 seconds is determined by: static btRigidBody::gDeactivationTime
|
||||||
|
@ -284,7 +284,7 @@ bool PhysicsEngine::addObject(ObjectMotionState* motionState) {
|
||||||
body = new btRigidBody(mass, motionState, shape, inertia);
|
body = new btRigidBody(mass, motionState, shape, inertia);
|
||||||
body->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);
|
body->setCollisionFlags(btCollisionObject::CF_STATIC_OBJECT);
|
||||||
body->updateInertiaTensor();
|
body->updateInertiaTensor();
|
||||||
motionState->_body = body;
|
motionState->setRigidBody(body);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ bool PhysicsEngine::addObject(ObjectMotionState* motionState) {
|
||||||
|
|
||||||
bool PhysicsEngine::removeObject(ObjectMotionState* motionState) {
|
bool PhysicsEngine::removeObject(ObjectMotionState* motionState) {
|
||||||
assert(motionState);
|
assert(motionState);
|
||||||
btRigidBody* body = motionState->_body;
|
btRigidBody* body = motionState->getRigidBody();
|
||||||
if (body) {
|
if (body) {
|
||||||
const btCollisionShape* shape = body->getCollisionShape();
|
const btCollisionShape* shape = body->getCollisionShape();
|
||||||
ShapeInfo shapeInfo;
|
ShapeInfo shapeInfo;
|
||||||
|
@ -309,7 +309,7 @@ bool PhysicsEngine::removeObject(ObjectMotionState* motionState) {
|
||||||
_dynamicsWorld->removeRigidBody(body);
|
_dynamicsWorld->removeRigidBody(body);
|
||||||
_shapeManager.releaseShape(shapeInfo);
|
_shapeManager.releaseShape(shapeInfo);
|
||||||
delete body;
|
delete body;
|
||||||
motionState->_body = NULL;
|
motionState->setRigidBody(NULL);
|
||||||
motionState->removeKinematicController();
|
motionState->removeKinematicController();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue