Overte C++ Documentation
ParabolaPick.h
1 //
2 // Created by Sam Gondelman 7/2/2018
3 // Copyright 2018 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 #ifndef hifi_ParabolaPick_h
9 #define hifi_ParabolaPick_h
10 
11 #include <RegisteredMetaTypes.h>
12 #include <Pick.h>
13 
14 class EntityItemID;
15 
16 class ParabolaPickResult : public PickResult {
17 public:
18  ParabolaPickResult() {}
19  ParabolaPickResult(const QVariantMap& pickVariant) : PickResult(pickVariant) {}
20  ParabolaPickResult(const IntersectionType type, const QUuid& objectID, float distance, float parabolicDistance, const glm::vec3& intersection, const PickParabola& parabola,
21  const glm::vec3& surfaceNormal = glm::vec3(NAN), const QVariantMap& extraInfo = QVariantMap()) :
22  PickResult(parabola.toVariantMap()), extraInfo(extraInfo), objectID(objectID), intersection(intersection), surfaceNormal(surfaceNormal), type(type), distance(distance), parabolicDistance(parabolicDistance), intersects(type != NONE) {
23  }
24 
25  ParabolaPickResult(const ParabolaPickResult& parabolaPickResult) : PickResult(parabolaPickResult.pickVariant) {
26  type = parabolaPickResult.type;
27  intersects = parabolaPickResult.intersects;
28  objectID = parabolaPickResult.objectID;
29  distance = parabolaPickResult.distance;
30  parabolicDistance = parabolaPickResult.parabolicDistance;
31  intersection = parabolaPickResult.intersection;
32  surfaceNormal = parabolaPickResult.surfaceNormal;
33  extraInfo = parabolaPickResult.extraInfo;
34  }
35 
36  QVariantMap extraInfo;
37  QUuid objectID;
38  glm::vec3 intersection { NAN };
39  glm::vec3 surfaceNormal { NAN };
40  IntersectionType type { NONE };
41  float distance { FLT_MAX };
42  float parabolicDistance { FLT_MAX };
43  bool intersects { false };
44 
45  /*@jsdoc
46  * An intersection result for a parabola pick.
47  *
48  * @typedef {object} ParabolaPickResult
49  * @property {number} type - The intersection type.
50  * @property {boolean} intersects - <code>true</code> if there's a valid intersection, <code>false</code> if there isn't.
51  * @property {Uuid} objectID - The ID of the intersected object. <code>null</code> for HUD or invalid intersections.
52  * @property {number} distance - The distance from the parabola origin to the intersection point in a straight line.
53  * @property {number} parabolicDistance - The distance from the parabola origin to the intersection point along the arc of
54  * the parabola.
55  * @property {Vec3} intersection - The intersection point in world coordinates.
56  * @property {Vec3} surfaceNormal - The surface normal at the intersected point. All <code>NaN</code>s if <code>type ==
57  * Picks.INTERSECTED_HUD</code>.
58  * @property {SubmeshIntersection} extraInfo - Additional intersection details for model objects, otherwise
59  * <code>{ }</code>.
60  * @property {PickParabola} parabola - The pick parabola that was used. Valid even if there is no intersection.
61  */
62  virtual QVariantMap toVariantMap() const override {
63  QVariantMap toReturn;
64  toReturn["type"] = type;
65  toReturn["intersects"] = intersects;
66  toReturn["objectID"] = objectID;
67  toReturn["distance"] = distance;
68  toReturn["parabolicDistance"] = parabolicDistance;
69  toReturn["intersection"] = vec3toVariant(intersection);
70  toReturn["surfaceNormal"] = vec3toVariant(surfaceNormal);
71  toReturn["parabola"] = PickResult::toVariantMap();
72  toReturn["extraInfo"] = extraInfo;
73  return toReturn;
74  }
75 
76  bool doesIntersect() const override { return intersects; }
77  bool checkOrFilterAgainstMaxDistance(float maxDistance) override { return parabolicDistance < maxDistance; }
78 
79  PickResultPointer compareAndProcessNewResult(const PickResultPointer& newRes) override {
80  auto newParabolaRes = std::static_pointer_cast<ParabolaPickResult>(newRes);
81  if (newParabolaRes->parabolicDistance < parabolicDistance) {
82  return std::make_shared<ParabolaPickResult>(*newParabolaRes);
83  } else {
84  return std::make_shared<ParabolaPickResult>(*this);
85  }
86  }
87 
88 };
89 
90 class ParabolaPick : public Pick<PickParabola> {
91 
92 public:
93  ParabolaPick(const glm::vec3& position, const glm::vec3& direction, float speed, const glm::vec3& acceleration, bool rotateAccelerationWithAvatar, bool rotateAccelerationWithParent, bool scaleWithParent, const PickFilter& filter, float maxDistance, bool enabled);
94 
95  PickType getType() const override { return PickType::Parabola; }
96 
97  PickParabola getMathematicalPick() const override;
98 
99  PickResultPointer getDefaultResult(const QVariantMap& pickVariant) const override { return std::make_shared<ParabolaPickResult>(pickVariant); }
100  PickResultPointer getEntityIntersection(const PickParabola& pick) override;
101  PickResultPointer getAvatarIntersection(const PickParabola& pick) override;
102  PickResultPointer getHUDIntersection(const PickParabola& pick) override;
103  Transform getResultTransform() const override;
104 
105 protected:
106  bool _rotateAccelerationWithAvatar;
107  bool _rotateAccelerationWithParent;
108  bool _scaleWithParent;
109  // Cached magnitude of _mathPick.velocity
110  float _speed;
111 };
112 
113 #endif // hifi_ParabolaPick_h
Abstract ID for editing model items. Used in EntityItem JS API.
Definition: EntityItemID.h:28