restore polymorphism for Box and Sphere entities

This commit is contained in:
Andrew Meadows 2015-01-30 16:18:50 -08:00
parent 80f6f718d0
commit bc52ba1d29
5 changed files with 24 additions and 17 deletions

View file

@ -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() << "---------------------------------------------";

View file

@ -51,6 +51,8 @@ public:
_color[BLUE_INDEX] = value.blue;
}
void computeShapeInfo(ShapeInfo& info) const;
virtual void debugDump() const;
protected:

View file

@ -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();
}
}

View file

@ -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 {

View file

@ -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,