From 85e7c6166b2e6542f6ad83ff0f7ea2cf4645d636 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 3 Dec 2014 12:10:26 -0800 Subject: [PATCH] support for spherical entities --- libraries/entities/src/BoxEntityItem.cpp | 14 +++----------- libraries/entities/src/BoxEntityItem.h | 2 ++ libraries/entities/src/EntityItem.cpp | 4 ++++ libraries/entities/src/EntityItem.h | 5 +++++ libraries/entities/src/SphereEntityItem.cpp | 6 ++++++ libraries/entities/src/SphereEntityItem.h | 2 ++ libraries/physics/src/EntityMotionState.cpp | 4 +--- 7 files changed, 23 insertions(+), 14 deletions(-) diff --git a/libraries/entities/src/BoxEntityItem.cpp b/libraries/entities/src/BoxEntityItem.cpp index ecd1306297..560ef05054 100644 --- a/libraries/entities/src/BoxEntityItem.cpp +++ b/libraries/entities/src/BoxEntityItem.cpp @@ -96,16 +96,8 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor()); } -/* -#ifdef USE_BULLET_PHYSICS -EntityMotionState* BoxEntityItem::createMotionState() { - if (!_motionState) { - _motionState = new EntityMotionState(this); - glm::vec3 extents = getDimensionsInMeters(); - _motionState->setVolume(extents.x * extents.y * extents.z); - } - return _motionState; +void BoxEntityItem::computeShapeInfo(ShapeInfo& info) const { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + info.setBox(halfExtents); } -#endif // USE_BULLET_PHYSICS -*/ diff --git a/libraries/entities/src/BoxEntityItem.h b/libraries/entities/src/BoxEntityItem.h index bea4f0c32a..7325432937 100644 --- a/libraries/entities/src/BoxEntityItem.h +++ b/libraries/entities/src/BoxEntityItem.h @@ -50,6 +50,8 @@ public: _color[GREEN_INDEX] = value.green; _color[BLUE_INDEX] = value.blue; } + + void computeShapeInfo(ShapeInfo& info) const; protected: rgbColor _color; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 928645b349..5e3d648b45 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -946,6 +946,10 @@ float EntityItem::getRadius() const { return radius; } +void EntityItem::computeShapeInfo(ShapeInfo& info) const { + info.clear(); +} + void EntityItem::recalculateCollisionShape() { AACube entityAACube = getMinimumAACube(); entityAACube.scale(TREE_SCALE); // scale to meters diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index e865b4a3f5..23f8695417 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -22,6 +22,7 @@ #include // for EncodeBitstreamParams class #include // for OctreeElement::AppendState #include +#include #include #include "EntityItemID.h" @@ -279,6 +280,7 @@ public: void applyHardCollision(const CollisionInfo& collisionInfo); virtual const Shape& getCollisionShapeInMeters() const { return _collisionShape; } virtual bool contains(const glm::vec3& point) const { return getAABox().contains(point); } + virtual void computeShapeInfo(ShapeInfo& info) const; // updateFoo() methods to be used when changes need to be accumulated in the _updateFlags void updatePosition(const glm::vec3& value); @@ -348,6 +350,9 @@ protected: void setRadius(float value); AACubeShape _collisionShape; + + // _physicsInfo is a hook reserved for use by the EntitySimulation, which is guaranteed to set _physicsInfo + // to a non-NULL value when the EntityItem has a representation in the physics engine. void* _physicsInfo; // only set by EntitySimulation SimulationState _simulationState; // only set by EntitySimulation diff --git a/libraries/entities/src/SphereEntityItem.cpp b/libraries/entities/src/SphereEntityItem.cpp index f5b8eb27e9..72c470931b 100644 --- a/libraries/entities/src/SphereEntityItem.cpp +++ b/libraries/entities/src/SphereEntityItem.cpp @@ -93,3 +93,9 @@ void SphereEntityItem::recalculateCollisionShape() { float largestDiameter = glm::max(dimensionsInMeters.x, dimensionsInMeters.y, dimensionsInMeters.z); _sphereShape.setRadius(largestDiameter / 2.0f); } + +void SphereEntityItem::computeShapeInfo(ShapeInfo& info) const { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + // TODO: support ellipsoid shapes + info.setSphere(halfExtents.x); +} diff --git a/libraries/entities/src/SphereEntityItem.h b/libraries/entities/src/SphereEntityItem.h index 21cb58223b..4a07ad5837 100644 --- a/libraries/entities/src/SphereEntityItem.h +++ b/libraries/entities/src/SphereEntityItem.h @@ -55,6 +55,8 @@ public: // TODO: implement proper contains for 3D ellipsoid //virtual bool contains(const glm::vec3& point) const; + + void computeShapeInfo(ShapeInfo& info) const; protected: virtual void recalculateCollisionShape(); diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index f08b32afb2..0620ae73aa 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -107,9 +107,7 @@ void EntityMotionState::applyGravity() const { } void EntityMotionState::computeShapeInfo(ShapeInfo& info) { - // HACK: for now we make everything a box. - glm::vec3 halfExtents = 0.5f * _entity->getDimensionsInMeters(); - info.setBox(halfExtents); + _entity->computeShapeInfo(info); } void EntityMotionState::getBoundingCubes(AACube& oldCube, AACube& newCube) {