add hook for ShapeInfo calculator

This commit is contained in:
Andrew Meadows 2017-09-07 09:29:04 -07:00 committed by LaShonda Hopper
parent 58501bd0b0
commit 9981a44b71
2 changed files with 19 additions and 3 deletions

View file

@ -51,6 +51,14 @@ namespace entity {
}
}
// shapeCalculator is a hook for external code that knows how to configure a ShapeInfo
// for given entity::Shape and dimensions
ShapeEntityItem::ShapeInfoCalculator shapeCalculator = nullptr;
void ShapeEntityItem::setShapeInfoCalulator(ShapeEntityItem::ShapeInfoCalculator callback) {
shapeCalculator = callback;
}
ShapeEntityItem::Pointer ShapeEntityItem::baseFactory(const EntityItemID& entityID, const EntityItemProperties& properties) {
Pointer entity(new ShapeEntityItem(entityID), [](EntityItem* ptr) { ptr->deleteLater(); });
entity->setProperties(properties);
@ -278,8 +286,14 @@ void ShapeEntityItem::computeShapeInfo(ShapeInfo& info) {
case entity::Shape::Icosahedron:
case entity::Shape::Cone:
{
//TODO WL21389: SHAPE_TYPE_SIMPLE_HULL and pointCollection (later)
_collisionShapeType = SHAPE_TYPE_ELLIPSOID;
if (shapeCalculator) {
shapeCalculator(info, _shape, getDimensions());
// shapeCalculator only supports convex shapes (e.g. SHAPE_TYPE_HULL)
// TODO: figure out how to support concave shapes
_collisionShapeType = SHAPE_TYPE_HULL;
} else {
_collisionShapeType = SHAPE_TYPE_ELLIPSOID;
}
}
break;
case entity::Shape::Torus:

View file

@ -34,7 +34,6 @@ namespace entity {
::QString stringFromShape(Shape shape);
}
class ShapeEntityItem : public EntityItem {
using Pointer = std::shared_ptr<ShapeEntityItem>;
static Pointer baseFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
@ -43,6 +42,9 @@ public:
static EntityItemPointer sphereFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
static EntityItemPointer boxFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
using ShapeInfoCalculator = std::function<void(ShapeInfo& info, entity::Shape shape, glm::vec3 dimensions)>;
static void setShapeInfoCalulator(ShapeInfoCalculator callback);
ShapeEntityItem(const EntityItemID& entityItemID);
void pureVirtualFunctionPlaceHolder() override { };