Overte C++ Documentation
StylusPointer.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_StylusPointer_h
9 #define hifi_StylusPointer_h
10 
11 #include <Pointer.h>
12 #include <shared/Bilateral.h>
13 #include <RegisteredMetaTypes.h>
14 
15 #include "StylusPick.h"
16 
17 class StylusPointer : public Pointer {
18  using Parent = Pointer;
19  using Ptr = std::shared_ptr<StylusPointer>;
20 
21 public:
22  StylusPointer(const QVariant& props, const QUuid& stylus, bool hover, bool enabled,
23  const glm::vec3& modelPositionOffset, const glm::quat& modelRotationOffset, const glm::vec3& modelDimensions);
24  ~StylusPointer();
25 
26  PickQuery::PickType getType() const override;
27 
28  void updateVisuals(const PickResultPointer& pickResult) override;
29 
30  // Styluses have three render states:
31  // default: "events on" -> render and hover/trigger
32  // "events off" -> render, don't hover/trigger
33  // "disabled" -> don't render, don't hover/trigger
34  void setRenderState(const std::string& state) override;
35  void editRenderState(const std::string& state, const QVariant& startProps, const QVariant& pathProps, const QVariant& endProps) override {}
36 
37  QVariantMap toVariantMap() const override;
38 
39  static QUuid buildStylus(const QVariantMap& properties);
40 
41 protected:
42  PickedObject getHoveredObject(const PickResultPointer& pickResult) override;
43  Buttons getPressedButtons(const PickResultPointer& pickResult) override;
44  glm::vec2 getScroll(const PickResultPointer& pickResult) override;
45 
46  bool shouldHover(const PickResultPointer& pickResult) override;
47  bool shouldTrigger(const PickResultPointer& pickResult) override;
48  virtual PickResultPointer getPickResultCopy(const PickResultPointer& pickResult) const override;
49 
50  PointerEvent buildPointerEvent(const PickedObject& target, const PickResultPointer& pickResult, const std::string& button = "", bool hover = true) override;
51 
52 private:
53  void show(const StylusTip& tip);
54  void hide();
55 
56  struct TriggerState {
57  PickedObject triggeredObject;
58  glm::vec3 intersection { NAN };
59  glm::vec2 triggerPos2D { NAN };
60  glm::vec3 surfaceNormal { NAN };
61  quint64 triggerStartTime { 0 };
62  bool deadspotExpired { true };
63  bool triggering { false };
64  bool wasTriggering { false };
65 
66  bool hovering { false };
67  };
68 
69  TriggerState _state;
70 
71  enum RenderState {
72  EVENTS_ON = 0,
73  EVENTS_OFF,
74  DISABLED
75  };
76 
77  RenderState _renderState { EVENTS_ON };
78 
79  QUuid _stylus;
80 
81  static bool isWithinBounds(float distance, float min, float max, float hysteresis);
82  static glm::vec3 findIntersection(const PickedObject& pickedObject, const glm::vec3& origin, const glm::vec3& direction);
83  static glm::vec2 findPos2D(const PickedObject& pickedObject, const glm::vec3& origin);
84 
85  bool _showing { true };
86 
87  glm::vec3 _modelPositionOffset;
88  glm::vec3 _modelDimensions;
89  glm::quat _modelRotationOffset;
90 
91 };
92 
93 #endif // hifi_StylusPointer_h
94 
95 
96 
97 
Represents a 2D or 3D pointer to the scripting engine. Exposed as PointerEvent
Definition: PointerEvent.h:32