Overte C++ Documentation
StylusPick.h
1 //
2 // Created by Bradley Austin Davis on 2017/10/24
3 // Copyright 2013-2017 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_StylusPick_h
9 #define hifi_StylusPick_h
10 
11 #include <Pick.h>
12 #include "RegisteredMetaTypes.h"
13 
14 class StylusPickResult : public PickResult {
15  using Side = bilateral::Side;
16 
17 public:
18  StylusPickResult() {}
19  StylusPickResult(const QVariantMap& pickVariant) : PickResult(pickVariant) {}
20  StylusPickResult(const IntersectionType type, const QUuid& objectID, float distance, const glm::vec3& intersection, const StylusTip& stylusTip,
21  const glm::vec3& surfaceNormal = glm::vec3(NAN)) :
22  PickResult(stylusTip.toVariantMap()), type(type), intersects(type != NONE), objectID(objectID), distance(distance), intersection(intersection), surfaceNormal(surfaceNormal) {
23  }
24 
25  StylusPickResult(const StylusPickResult& stylusPickResult) : PickResult(stylusPickResult.pickVariant) {
26  type = stylusPickResult.type;
27  intersects = stylusPickResult.intersects;
28  objectID = stylusPickResult.objectID;
29  distance = stylusPickResult.distance;
30  intersection = stylusPickResult.intersection;
31  surfaceNormal = stylusPickResult.surfaceNormal;
32  }
33 
34  StylusPickResult& operator=(const StylusPickResult &right) = default;
35 
36  IntersectionType type { NONE };
37  bool intersects { false };
38  QUuid objectID;
39  float distance { FLT_MAX };
40  glm::vec3 intersection { NAN };
41  glm::vec3 surfaceNormal { NAN };
42 
43  /*@jsdoc
44  * An intersection result for a stylus pick.
45  *
46  * @typedef {object} StylusPickResult
47  * @property {number} type - The intersection type.
48  * @property {boolean} intersects - <code>true</code> if there's a valid intersection, <code>false</code> if there isn't.
49  * @property {Uuid} objectID - The ID of the intersected object. <code>null</code> for invalid intersections.
50  * @property {number} distance - The distance to the intersection point from the stylus tip.
51  * @property {Vec3} intersection - The intersection point in world coordinates.
52  * @property {Vec3} surfaceNormal - The surface normal at the intersected point.
53  * @property {StylusTip} stylusTip - The stylus tip at the time of the result. Valid even if there is no intersection.
54  */
55  virtual QVariantMap toVariantMap() const override {
56  QVariantMap toReturn;
57  toReturn["type"] = type;
58  toReturn["intersects"] = intersects;
59  toReturn["objectID"] = objectID;
60  toReturn["distance"] = distance;
61  toReturn["intersection"] = vec3toVariant(intersection);
62  toReturn["surfaceNormal"] = vec3toVariant(surfaceNormal);
63  toReturn["stylusTip"] = PickResult::toVariantMap();
64  return toReturn;
65  }
66 
67  bool doesIntersect() const override { return intersects; }
68  std::shared_ptr<PickResult> compareAndProcessNewResult(const std::shared_ptr<PickResult>& newRes) override;
69  bool checkOrFilterAgainstMaxDistance(float maxDistance) override;
70 };
71 
72 class StylusPick : public Pick<StylusTip> {
73  using Side = bilateral::Side;
74 public:
75  StylusPick(Side side, const PickFilter& filter, float maxDistance, bool enabled, const glm::vec3& tipOffset);
76 
77  PickType getType() const override { return PickType::Stylus; }
78  StylusTip getMathematicalPick() const override;
79  PickResultPointer getDefaultResult(const QVariantMap& pickVariant) const override;
80  PickResultPointer getEntityIntersection(const StylusTip& pick) override;
81  PickResultPointer getAvatarIntersection(const StylusTip& pick) override;
82  PickResultPointer getHUDIntersection(const StylusTip& pick) override;
83  Transform getResultTransform() const override;
84 
85  bool isLeftHand() const override { return _mathPick.side == Side::Left; }
86  bool isRightHand() const override { return _mathPick.side == Side::Right; }
87  bool isMouse() const override { return false; }
88 
89  static float WEB_STYLUS_LENGTH;
90 };
91 
92 #endif // hifi_StylusPick_h