Overte C++ Documentation
ShapeEntityItem.h
1 //
2 // Created by Bradley Austin Davis on 2016/05/09
3 // Copyright 2013 High Fidelity, Inc.
4 //
5 // Distributed under the Apache License, Version 2.0.
6 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
7 //
8 
9 #ifndef hifi_ShapeEntityItem_h
10 #define hifi_ShapeEntityItem_h
11 
12 #include "EntityItem.h"
13 
14 #include "PulsePropertyGroup.h"
15 
16 namespace entity {
17  enum Shape {
18  Triangle,
19  Quad,
20  Hexagon,
21  Octagon,
22  Circle,
23  Cube,
24  Sphere,
25  Tetrahedron,
26  Octahedron,
27  Dodecahedron,
28  Icosahedron,
29  Torus,
30  Cone,
31  Cylinder,
32  NUM_SHAPES,
33  };
34 
35  Shape shapeFromString(const ::QString& shapeString);
36  QString stringFromShape(Shape shape);
37 }
38 
39 class ShapeEntityItem : public EntityItem {
40  using Pointer = std::shared_ptr<ShapeEntityItem>;
41  static Pointer baseFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
42 public:
43  static EntityItemPointer factory(const EntityItemID& entityID, const EntityItemProperties& properties);
44  static EntityItemPointer sphereFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
45  static EntityItemPointer boxFactory(const EntityItemID& entityID, const EntityItemProperties& properties);
46 
47  using ShapeInfoCalculator = std::function<void( const ShapeEntityItem * const shapeEntity, ShapeInfo& info)>;
48  static void setShapeInfoCalulator(ShapeInfoCalculator callback);
49 
50  ShapeEntityItem(const EntityItemID& entityItemID);
51 
52  void pureVirtualFunctionPlaceHolder() override { };
53  // Triggers warnings on OSX
54  //ALLOW_INSTANTIATION
55 
56  // methods for getting/setting all properties of an entity
57  EntityItemProperties getProperties(const EntityPropertyFlags& desiredProperties, bool allowEmptyDesiredProperties) const override;
58  bool setSubClassProperties(const EntityItemProperties& properties) override;
59 
60  EntityPropertyFlags getEntityProperties(EncodeBitstreamParams& params) const override;
61 
62  void appendSubclassData(OctreePacketData* packetData, EncodeBitstreamParams& params,
63  EntityTreeElementExtraEncodeDataPointer entityTreeElementExtraEncodeData,
64  EntityPropertyFlags& requestedProperties,
65  EntityPropertyFlags& propertyFlags,
66  EntityPropertyFlags& propertiesDidntFit,
67  int& propertyCount,
68  OctreeElement::AppendState& appendState) const override;
69 
70  int readEntitySubclassDataFromBuffer(const unsigned char* data, int bytesLeftToRead,
71  ReadBitstreamToTreeParams& args,
72  EntityPropertyFlags& propertyFlags, bool overwriteLocalData,
73  bool& somethingChanged) override;
74 
75  entity::Shape getShape() const;
76  void setShape(const entity::Shape& shape);
77  void setShape(const QString& shape) { setShape(entity::shapeFromString(shape)); }
78 
79  float getAlpha() const;
80  void setAlpha(float alpha);
81 
82  glm::u8vec3 getColor() const;
83  void setColor(const glm::u8vec3& value);
84 
85  void setUnscaledDimensions(const glm::vec3& value) override;
86 
87  bool supportsDetailedIntersection() const override;
88  bool findDetailedRayIntersection(const glm::vec3& origin, const glm::vec3& direction,
89  const glm::vec3& viewFrustumPos, OctreeElementPointer& element,
90  float& distance, BoxFace& face, glm::vec3& surfaceNormal,
91  QVariantMap& extraInfo, bool precisionPicking) const override;
92  bool findDetailedParabolaIntersection(const glm::vec3& origin, const glm::vec3& velocity,
93  const glm::vec3& acceleration, const glm::vec3& viewFrustumPos, OctreeElementPointer& element,
94  float& parabolicDistance, BoxFace& face, glm::vec3& surfaceNormal,
95  QVariantMap& extraInfo, bool precisionPicking) const override;
96  bool getRotateForPicking() const override;
97 
98  void debugDump() const override;
99 
100  virtual void computeShapeInfo(ShapeInfo& info) override;
101  virtual ShapeType getShapeType() const override;
102 
103  PulsePropertyGroup getPulseProperties() const;
104 
105  void setUserData(const QString& value) override;
106 
107 protected:
108  glm::u8vec3 _color;
109  float _alpha { 1.0f };
110  PulsePropertyGroup _pulseProperties;
111  entity::Shape _shape { entity::Shape::Sphere };
112 
116  ShapeType _collisionShapeType { ShapeType::SHAPE_TYPE_ELLIPSOID };
117 };
118 
119 #endif // hifi_ShapeEntityItem_h
Definition: EntityItem.h:82
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28
Definition: EntityItemProperties.h:106
Handles packing of the data portion of PacketType_OCTREE_DATA messages.
Definition: OctreePacketData.h:93