overte-HifiExperiments/libraries/entities/src/ShapeEntityItem.h
2018-03-09 08:35:18 -08:00

120 lines
4.6 KiB
C++

//
// Created by Bradley Austin Davis on 2016/05/09
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_ShapeEntityItem_h
#define hifi_ShapeEntityItem_h
#include "EntityItem.h"
namespace entity {
enum Shape {
Triangle,
Quad,
Hexagon,
Octagon,
Circle,
Cube,
Sphere,
Tetrahedron,
Octahedron,
Dodecahedron,
Icosahedron,
Torus,
Cone,
Cylinder,
NUM_SHAPES,
};
Shape shapeFromString(const ::QString& shapeString);
::QString stringFromShape(Shape shape);
}
class ShapeEntityItem : public EntityItem {
using Pointer = std::shared_ptr<ShapeEntityItem>;
static Pointer baseFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
public:
static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
static EntityItemPointer sphereFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
static EntityItemPointer boxFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
using ShapeInfoCalculator = std::function<void( const ShapeEntityItem * const shapeEntity, ShapeInfo& info)>;
static void setShapeInfoCalulator(ShapeInfoCalculator callback);
ShapeEntityItem(const EntityItemID& entityItemID);
void pureVirtualFunctionPlaceHolder() override { };
// Triggers warnings on OSX
//ALLOW_INSTANTIATION
// methods for getting/setting all properties of an entity
EntityItemProperties getProperties(EntityPropertyFlags desiredProperties = EntityPropertyFlags()) const override;
bool setProperties(const EntityItemProperties& properties) override;
EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override;
void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
EntityTreeElementExtraEncodeDataPointer modelTreeElementExtraEncodeData,
EntityPropertyFlags& requestedProperties,
EntityPropertyFlags& propertyFlags,
EntityPropertyFlags& propertiesDidntFit,
int& propertyCount,
OctreeElement::AppendState& appendState) const override;
int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
ReadBitstreamToTreeParams& args,
EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
bool& somethingChanged) override;
entity::Shape getShape() const { return _shape; }
void setShape(const entity::Shape& shape);
void setShape(const QString& shape) { setShape(entity::shapeFromString(shape)); }
float getAlpha() const { return _alpha; };
void setAlpha(float alpha);
const rgbColor& getColor() const { return _color; }
void setColor(const rgbColor& value);
void setUnscaledDimensions(const glm::vec3& value) override;
xColor getXColor() const;
void setColor(const xColor& value);
QColor getQColor() const;
void setColor(const QColor& value);
bool shouldBePhysical() const override { return !isDead(); }
bool supportsDetailedRayIntersection() const override;
bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
OctreeElementPointer& element, float& distance,
BoxFace& face, glm::vec3& surfaceNormal,
QVariantMap& extraInfo, bool precisionPicking) const override;
void debugDump() const override;
virtual void computeShapeInfo(ShapeInfo& info) override;
virtual ShapeType getShapeType() const override;
std::shared_ptr<graphics::Material> getMaterial() { return _material; }
protected:
float _alpha { 1 };
rgbColor _color;
entity::Shape _shape { entity::Shape::Sphere };
//! This is SHAPE_TYPE_ELLIPSOID rather than SHAPE_TYPE_NONE to maintain
//! prior functionality where new or unsupported shapes are treated as
//! ellipsoids.
ShapeType _collisionShapeType{ ShapeType::SHAPE_TYPE_ELLIPSOID };
std::shared_ptr<graphics::Material> _material;
};
#endif // hifi_ShapeEntityItem_h