mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 01:03:57 +02:00
const shapes, and use *MotionState::setShape()
This commit is contained in:
parent
25fb7aacad
commit
daff897fc4
4 changed files with 21 additions and 19 deletions
|
@ -46,7 +46,7 @@ bool entityTreeIsLocked() {
|
|||
|
||||
|
||||
EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer entity) :
|
||||
ObjectMotionState(shape),
|
||||
ObjectMotionState(nullptr),
|
||||
_entityPtr(entity),
|
||||
_entity(entity.get()),
|
||||
_serverPosition(0.0f),
|
||||
|
@ -71,6 +71,9 @@ EntityMotionState::EntityMotionState(btCollisionShape* shape, EntityItemPointer
|
|||
assert(_entity);
|
||||
assert(entityTreeIsLocked());
|
||||
setMass(_entity->computeMass());
|
||||
// we need the side-effects of EntityMotionState::setShape() so we call it explicitly here
|
||||
// rather than pass the legit shape pointer to the ObjectMotionState ctor above.
|
||||
setShape(shape);
|
||||
}
|
||||
|
||||
EntityMotionState::~EntityMotionState() {
|
||||
|
@ -264,17 +267,16 @@ bool EntityMotionState::isReadyToComputeShape() const {
|
|||
}
|
||||
|
||||
// virtual and protected
|
||||
btCollisionShape* EntityMotionState::computeNewShape() {
|
||||
const btCollisionShape* EntityMotionState::computeNewShape() {
|
||||
ShapeInfo shapeInfo;
|
||||
assert(entityTreeIsLocked());
|
||||
_entity->computeShapeInfo(shapeInfo);
|
||||
return getShapeManager()->getShape(shapeInfo);
|
||||
}
|
||||
|
||||
void EntityMotionState::setShape(btCollisionShape* shape) {
|
||||
bool shapeChanged = (_shape != shape);
|
||||
ObjectMotionState::setShape(shape);
|
||||
if (shapeChanged) {
|
||||
void EntityMotionState::setShape(const btCollisionShape* shape) {
|
||||
if (_shape != shape) {
|
||||
ObjectMotionState::setShape(shape);
|
||||
_entity->setCollisionShape(_shape);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -89,8 +89,8 @@ protected:
|
|||
#endif
|
||||
|
||||
bool isReadyToComputeShape() const override;
|
||||
btCollisionShape* computeNewShape() override;
|
||||
void setShape(btCollisionShape* shape) override;
|
||||
const btCollisionShape* computeNewShape() override;
|
||||
void setShape(const btCollisionShape* shape) override;
|
||||
void setMotionType(PhysicsMotionType motionType) override;
|
||||
|
||||
// In the glorious future (when entities lib depends on physics lib) the EntityMotionState will be
|
||||
|
|
|
@ -62,14 +62,13 @@ ShapeManager* ObjectMotionState::getShapeManager() {
|
|||
return shapeManager;
|
||||
}
|
||||
|
||||
ObjectMotionState::ObjectMotionState(btCollisionShape* shape) :
|
||||
ObjectMotionState::ObjectMotionState(const btCollisionShape* shape) :
|
||||
_motionType(MOTION_TYPE_STATIC),
|
||||
_shape(nullptr),
|
||||
_shape(shape),
|
||||
_body(nullptr),
|
||||
_mass(0.0f),
|
||||
_lastKinematicStep(worldSimulationStep)
|
||||
{
|
||||
setShape(shape);
|
||||
}
|
||||
|
||||
ObjectMotionState::~ObjectMotionState() {
|
||||
|
@ -154,12 +153,13 @@ void ObjectMotionState::setRigidBody(btRigidBody* body) {
|
|||
_body = body;
|
||||
if (_body) {
|
||||
_body->setUserPointer(this);
|
||||
assert(_body->getCollisionShape() == _shape);
|
||||
}
|
||||
updateCCDConfiguration();
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectMotionState::setShape(btCollisionShape* shape) {
|
||||
void ObjectMotionState::setShape(const btCollisionShape* shape) {
|
||||
if (_shape != shape) {
|
||||
if (_shape) {
|
||||
getShapeManager()->releaseShape(_shape);
|
||||
|
@ -254,7 +254,7 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine*
|
|||
if (!isReadyToComputeShape()) {
|
||||
return false;
|
||||
}
|
||||
btCollisionShape* newShape = computeNewShape();
|
||||
const btCollisionShape* newShape = computeNewShape();
|
||||
if (!newShape) {
|
||||
qCDebug(physics) << "Warning: failed to generate new shape!";
|
||||
// failed to generate new shape! --> keep old shape and remove shape-change flag
|
||||
|
@ -274,7 +274,7 @@ bool ObjectMotionState::handleHardAndEasyChanges(uint32_t& flags, PhysicsEngine*
|
|||
// and clear the reference we just created
|
||||
getShapeManager()->releaseShape(_shape);
|
||||
} else {
|
||||
_body->setCollisionShape(newShape);
|
||||
_body->setCollisionShape(const_cast<btCollisionShape*>(newShape));
|
||||
setShape(newShape);
|
||||
updateCCDConfiguration();
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public:
|
|||
static void setShapeManager(ShapeManager* manager);
|
||||
static ShapeManager* getShapeManager();
|
||||
|
||||
ObjectMotionState(btCollisionShape* shape);
|
||||
ObjectMotionState(const btCollisionShape* shape);
|
||||
~ObjectMotionState();
|
||||
|
||||
virtual void handleEasyChanges(uint32_t& flags);
|
||||
|
@ -110,7 +110,7 @@ public:
|
|||
|
||||
virtual PhysicsMotionType computePhysicsMotionType() const = 0;
|
||||
|
||||
btCollisionShape* getShape() const { return _shape; }
|
||||
const btCollisionShape* getShape() const { return _shape; }
|
||||
btRigidBody* getRigidBody() const { return _body; }
|
||||
|
||||
virtual bool isMoving() const = 0;
|
||||
|
@ -150,17 +150,17 @@ public:
|
|||
|
||||
protected:
|
||||
virtual bool isReadyToComputeShape() const = 0;
|
||||
virtual btCollisionShape* computeNewShape() = 0;
|
||||
virtual const btCollisionShape* computeNewShape() = 0;
|
||||
virtual void setMotionType(PhysicsMotionType motionType);
|
||||
void updateCCDConfiguration();
|
||||
|
||||
void setRigidBody(btRigidBody* body);
|
||||
virtual void setShape(btCollisionShape* shape);
|
||||
virtual void setShape(const btCollisionShape* shape);
|
||||
|
||||
MotionStateType _type = MOTIONSTATE_TYPE_INVALID; // type of MotionState
|
||||
PhysicsMotionType _motionType; // type of motion: KINEMATIC, DYNAMIC, or STATIC
|
||||
|
||||
btCollisionShape* _shape;
|
||||
const btCollisionShape* _shape;
|
||||
btRigidBody* _body;
|
||||
float _mass;
|
||||
|
||||
|
|
Loading…
Reference in a new issue