From b2dfa49a6ffe600bb3af355259c0ea2ab6eccb10 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 15 Jul 2016 15:24:57 -0700 Subject: [PATCH] stubbery for alerting entity that shape changed --- .../entities-renderer/src/RenderableModelEntityItem.h | 2 ++ libraries/entities/src/EntityItem.h | 7 +++++++ libraries/physics/src/EntityMotionState.cpp | 8 ++++++++ libraries/physics/src/EntityMotionState.h | 7 ++++--- libraries/physics/src/ObjectMotionState.h | 2 +- 5 files changed, 22 insertions(+), 4 deletions(-) diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.h b/libraries/entities-renderer/src/RenderableModelEntityItem.h index a3d9e4db98..22469cf0ef 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.h +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.h @@ -61,6 +61,8 @@ public: virtual bool isReadyToComputeShape() override; virtual void computeShapeInfo(ShapeInfo& info) override; + void setCollisionShape(const btCollisionShape* shape) override {} + virtual bool contains(const glm::vec3& point) const override; virtual bool shouldBePhysical() const override; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 9fe83b53cb..1ad1d938a7 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -44,6 +44,7 @@ class EntityTreeElementExtraEncodeData; class EntityActionInterface; class EntityItemProperties; class EntityTree; +class btCollisionShape; typedef std::shared_ptr EntityTreePointer; typedef std::shared_ptr EntityActionPointer; typedef std::shared_ptr EntityTreeElementPointer; @@ -324,6 +325,12 @@ public: /// return preferred shape type (actual physical shape may differ) virtual ShapeType getShapeType() const { return SHAPE_TYPE_NONE; } + virtual void setCollisionShape(const btCollisionShape* shape) {} + + // these are only needed because the names don't match + virtual const glm::quat getRotation() const { return getOrientation(); } + virtual void setRotation(glm::quat orientation) { setOrientation(orientation); } + // updateFoo() methods to be used when changes need to be accumulated in the _dirtyFlags virtual void updateRegistrationPoint(const glm::vec3& value); void updatePosition(const glm::vec3& value); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 08d207fa72..4b6823dd8a 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -271,6 +271,14 @@ btCollisionShape* EntityMotionState::computeNewShape() { return getShapeManager()->getShape(shapeInfo); } +void EntityMotionState::setShape(btCollisionShape* shape) { + bool shapeChanged = (_shape != shape); + ObjectMotionState::setShape(shape); + if (shapeChanged) { + _entity->setCollisionShape(_shape); + } +} + bool EntityMotionState::isCandidateForOwnership() const { assert(_body); assert(_entity); diff --git a/libraries/physics/src/EntityMotionState.h b/libraries/physics/src/EntityMotionState.h index 8f1532bf8f..2c39da9164 100644 --- a/libraries/physics/src/EntityMotionState.h +++ b/libraries/physics/src/EntityMotionState.h @@ -88,9 +88,10 @@ protected: bool entityTreeIsLocked() const; #endif - virtual bool isReadyToComputeShape() const override; - virtual btCollisionShape* computeNewShape() override; - virtual void setMotionType(PhysicsMotionType motionType); + bool isReadyToComputeShape() const override; + btCollisionShape* computeNewShape() override; + void setShape(btCollisionShape* shape) override; + void setMotionType(PhysicsMotionType motionType) override; // In the glorious future (when entities lib depends on physics lib) the EntityMotionState will be // properly "owned" by the EntityItem and will be deleted by it in the dtor. In pursuit of that diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index ca9b80a3b3..ccaef17fd1 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -151,7 +151,7 @@ public: protected: virtual bool isReadyToComputeShape() const = 0; virtual btCollisionShape* computeNewShape() = 0; - void setMotionType(PhysicsMotionType motionType); + virtual void setMotionType(PhysicsMotionType motionType); void updateCCDConfiguration(); void setRigidBody(btRigidBody* body);