From bc52ba1d291d6c7b41cd3f9dd2f9b233b47d4d4b Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 30 Jan 2015 16:18:50 -0800 Subject: [PATCH] restore polymorphism for Box and Sphere entities --- libraries/entities/src/BoxEntityItem.cpp | 5 ++++ libraries/entities/src/BoxEntityItem.h | 2 ++ libraries/entities/src/EntityItem.cpp | 26 +++++++-------------- libraries/entities/src/SphereEntityItem.cpp | 6 +++++ libraries/entities/src/SphereEntityItem.h | 2 ++ 5 files changed, 24 insertions(+), 17 deletions(-) diff --git a/libraries/entities/src/BoxEntityItem.cpp b/libraries/entities/src/BoxEntityItem.cpp index 1e8c811122..25ef2e6aaf 100644 --- a/libraries/entities/src/BoxEntityItem.cpp +++ b/libraries/entities/src/BoxEntityItem.cpp @@ -96,6 +96,11 @@ void BoxEntityItem::appendSubclassData(OctreePacketData* packetData, EncodeBitst APPEND_ENTITY_PROPERTY(PROP_COLOR, appendColor, getColor()); } +void BoxEntityItem::computeShapeInfo(ShapeInfo& info) const { + glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); + info.setBox(halfExtents); +} + void BoxEntityItem::debugDump() const { quint64 now = usecTimestampNow(); qDebug() << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------"; diff --git a/libraries/entities/src/BoxEntityItem.h b/libraries/entities/src/BoxEntityItem.h index a9c3e724a7..8d68a13158 100644 --- a/libraries/entities/src/BoxEntityItem.h +++ b/libraries/entities/src/BoxEntityItem.h @@ -51,6 +51,8 @@ public: _color[BLUE_INDEX] = value.blue; } + void computeShapeInfo(ShapeInfo& info) const; + virtual void debugDump() const; protected: diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 68b5d1bb05..fa9487c6f6 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1021,25 +1021,17 @@ float EntityItem::getRadius() const { } void EntityItem::computeShapeInfo(ShapeInfo& info) const { - info.clear(); - if (_type == EntityTypes::Sphere) { - glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); - // TODO: support ellipsoid shapes - info.setSphere(halfExtents.x); - } else if (_type == EntityTypes::Box) { + // HACK: Default first first approximation is to boxify the entity... but only if it is small enough. + // The limit here is chosen to something that most avatars could not comfortably fit inside + // to prevent houses from getting boxified... we don't want the things inside houses to + // collide with a house as if it were a giant solid block. + const float MAX_SIZE_FOR_BOXIFICATION_HACK = 3.0f; + float diagonal = glm::length(getDimensionsInMeters()); + if (diagonal < MAX_SIZE_FOR_BOXIFICATION_HACK) { glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); info.setBox(halfExtents); - } else if (_type == EntityTypes::Model) { - // For first approximation we just boxify all models... but only if they are small enough. - // The limit here is chosen to something that most avatars could not comfortably fit inside - // to prevent houses from getting boxified... we don't want the things inside houses to - // collide with a house as if it were a giant solid block. - const float MAX_SIZE_FOR_BOXIFICATION_HACK = 3.0f; - float diagonal = glm::length(getDimensionsInMeters()); - if (diagonal < MAX_SIZE_FOR_BOXIFICATION_HACK) { - glm::vec3 halfExtents = 0.5f * getDimensionsInMeters(); - info.setBox(halfExtents); - } + } else { + info.clear(); } } diff --git a/libraries/entities/src/SphereEntityItem.cpp b/libraries/entities/src/SphereEntityItem.cpp index 865fb88463..181e5851f6 100644 --- a/libraries/entities/src/SphereEntityItem.cpp +++ b/libraries/entities/src/SphereEntityItem.cpp @@ -101,6 +101,12 @@ void SphereEntityItem::recalculateCollisionShape() { _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); +} + bool SphereEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face, void** intersectedObject, bool precisionPicking) const { diff --git a/libraries/entities/src/SphereEntityItem.h b/libraries/entities/src/SphereEntityItem.h index fdc0b7f866..f76c9f5600 100644 --- a/libraries/entities/src/SphereEntityItem.h +++ b/libraries/entities/src/SphereEntityItem.h @@ -56,6 +56,8 @@ public: // TODO: implement proper contains for 3D ellipsoid //virtual bool contains(const glm::vec3& point) const; + void computeShapeInfo(ShapeInfo& info) const; + virtual bool supportsDetailedRayIntersection() const { return true; } virtual bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction, bool& keepSearching, OctreeElement*& element, float& distance, BoxFace& face,