added virtual ObjectMotionState::setShape()

This commit is contained in:
Andrew Meadows 2016-07-15 14:11:40 -07:00
parent cbacb02010
commit 1ed76ae442
2 changed files with 21 additions and 19 deletions

View file

@ -64,16 +64,17 @@ ShapeManager* ObjectMotionState::getShapeManager() {
ObjectMotionState::ObjectMotionState(btCollisionShape* shape) :
_motionType(MOTION_TYPE_STATIC),
_shape(shape),
_shape(nullptr),
_body(nullptr),
_mass(0.0f),
_lastKinematicStep(worldSimulationStep)
{
setShape(shape);
}
ObjectMotionState::~ObjectMotionState() {
assert(!_body);
releaseShape();
setShape(nullptr);
_type = MOTIONSTATE_TYPE_INVALID;
}
@ -114,13 +115,6 @@ glm::vec3 ObjectMotionState::getBodyAngularVelocity() const {
return bulletToGLM(_body->getAngularVelocity());
}
void ObjectMotionState::releaseShape() {
if (_shape) {
shapeManager->releaseShape(_shape);
_shape = nullptr;
}
}
void ObjectMotionState::setMotionType(PhysicsMotionType motionType) {
_motionType = motionType;
}
@ -165,6 +159,15 @@ void ObjectMotionState::setRigidBody(btRigidBody* body) {
}
}
void ObjectMotionState::setShape(btCollisionShape* shape) {
if (_shape != shape) {
if (_shape) {
getShapeManager()->releaseShape(_shape);
}
_shape = shape;
}
}
void ObjectMotionState::handleEasyChanges(uint32_t& flags) {
if (flags & Simulation::DIRTY_POSITION) {
btTransform worldTrans = _body->getWorldTransform();
@ -265,15 +268,15 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine*
return true;
}
}
getShapeManager()->releaseShape(_shape);
if (_shape != newShape) {
_shape = newShape;
_body->setCollisionShape(_shape);
updateCCDConfiguration();
} else {
// huh... the shape didn't actually change, so we clear the DIRTY_SHAPE flag
if (_shape == newShape) {
// the shape didn't actually change, so we clear the DIRTY_SHAPE flag
flags &= ~Simulation::DIRTY_SHAPE;
// and clear the reference we just created
getShapeManager()->releaseShape(_shape);
} else {
_body->setCollisionShape(newShape);
setShape(newShape);
updateCCDConfiguration();
}
}
if (flags & EASY_DIRTY_PHYSICS_FLAGS) {

View file

@ -113,8 +113,6 @@ public:
btCollisionShape* getShape() const { return _shape; }
btRigidBody* getRigidBody() const { return _body; }
void releaseShape();
virtual bool isMoving() const = 0;
// These pure virtual methods must be implemented for each MotionState type
@ -157,6 +155,7 @@ protected:
void updateCCDConfiguration();
void setRigidBody(btRigidBody* body);
virtual void setShape(btCollisionShape* shape);
MotionStateType _type = MOTIONSTATE_TYPE_INVALID; // type of MotionState
PhysicsMotionType _motionType; // type of motion: KINEMATIC, DYNAMIC, or STATIC