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  bool shouldHover(const PickResultPointer& pickResult) override;
45  bool shouldTrigger(const PickResultPointer& pickResult) override;
46  virtual PickResultPointer getPickResultCopy(const PickResultPointer& pickResult) const override;
47 
48  PointerEvent buildPointerEvent(const PickedObject& target, const PickResultPointer& pickResult, const std::string& button = "", bool hover = true) override;
49 
50 private:
51  void show(const StylusTip& tip);
52  void hide();
53 
54  struct TriggerState {
55  PickedObject triggeredObject;
56  glm::vec3 intersection { NAN };
57  glm::vec2 triggerPos2D { NAN };
58  glm::vec3 surfaceNormal { NAN };
59  quint64 triggerStartTime { 0 };
60  bool deadspotExpired { true };
61  bool triggering { false };
62  bool wasTriggering { false };
63 
64  bool hovering { false };
65  };
66 
67  TriggerState _state;
68 
69  enum RenderState {
70  EVENTS_ON = 0,
71  EVENTS_OFF,
72  DISABLED
73  };
74 
75  RenderState _renderState { EVENTS_ON };
76 
77  QUuid _stylus;
78 
79  static bool isWithinBounds(float distance, float min, float max, float hysteresis);
80  static glm::vec3 findIntersection(const PickedObject& pickedObject, const glm::vec3& origin, const glm::vec3& direction);
81  static glm::vec2 findPos2D(const PickedObject& pickedObject, const glm::vec3& origin);
82 
83  bool _showing { true };
84 
85  glm::vec3 _modelPositionOffset;
86  glm::vec3 _modelDimensions;
87  glm::quat _modelRotationOffset;
88 
89 };
90 
91 #endif // hifi_StylusPointer_h
92 
93 
94 
95 
Represents a 2D or 3D pointer to the scripting engine. Exposed as PointerEvent
Definition: PointerEvent.h:30