Overte C++ Documentation
VisionSqueeze.h
1 //
2 // VisionSqueeze.h
3 // interface/src
4 //
5 // Created by Seth Alves on 2019-3-13.
6 // Copyright 2019 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_VisionSqueeze_h
13 #define hifi_VisionSqueeze_h
14 
15 #include <memory>
16 #include <glm/glm.hpp>
17 
18 #include <SettingHandle.h>
19 
20 static const float DEFAULT_VISION_SQUEEZE_TURNING_X_FACTOR = 0.51f;
21 static const float DEFAULT_VISION_SQUEEZE_TURNING_Y_FACTOR = 0.36f;
22 static const float DEFAULT_VISION_SQUEEZE_UNSQUEEZE_DELAY = 0.2f; // seconds
23 static const float DEFAULT_VISION_SQUEEZE_UNSQUEEZE_SPEED = 3.0f;
24 static const float DEFAULT_VISION_SQUEEZE_TRANSITION = 0.25f;
25 static const int DEFAULT_VISION_SQUEEZE_PER_EYE = 1;
26 static const float DEFAULT_VISION_SQUEEZE_GROUND_PLANE_Y = 0.0f;
27 static const float DEFAULT_VISION_SQUEEZE_SPOTLIGHT_SIZE = 6.0f;
28 
29 
30 class VisionSqueeze {
31 
32 public:
33 
34  VisionSqueeze();
35 
36  bool getVisionSqueezeEnabled() const { return _visionSqueezeEnabled; }
37  void setVisionSqueezeEnabled(bool value);
38  float getVisionSqueezeRatioX() const { return _visionSqueezeRatioX; }
39  float getVisionSqueezeRatioY() const { return _visionSqueezeRatioY; }
40  void setVisionSqueezeRatioX(float value);
41  void setVisionSqueezeRatioY(float value);
42  float getVisionSqueezeUnSqueezeDelay() const { return _visionSqueezeUnSqueezeDelay; }
43  void setVisionSqueezeUnSqueezeDelay(float value);
44  float getVisionSqueezeUnSqueezeSpeed() const { return _visionSqueezeUnSqueezeSpeed; }
45  void setVisionSqueezeUnSqueezeSpeed(float value);
46  float getVisionSqueezeTransition() const { return _visionSqueezeTransition; }
47  void setVisionSqueezeTransition(float value);
48  int getVisionSqueezePerEye() const { return _visionSqueezePerEye; }
49  void setVisionSqueezePerEye(int value);
50  float getVisionSqueezeGroundPlaneY() const { return _visionSqueezeGroundPlaneY; }
51  void setVisionSqueezeGroundPlaneY(float value);
52  float getVisionSqueezeSpotlightSize() const { return _visionSqueezeSpotlightSize; }
53  void setVisionSqueezeSpotlightSize(float value);
54  float getVisionSqueezeTurningXFactor() const { return _visionSqueezeTurningXFactor; }
55  void setVisionSqueezeTurningXFactor(float value);
56  float getVisionSqueezeTurningYFactor() const { return _visionSqueezeTurningYFactor; }
57  void setVisionSqueezeTurningYFactor(float value);
58 
59  void updateVisionSqueeze(const glm::mat4& sensorToWorldMatrix, float deltaTime);
60 
61  // state variable accessors used by Application.cpp...
62  bool getSqueezeVision() const { return _squeezeVision; }
63  void setSqueezeVision(bool value) { _squeezeVision = value; }
64  bool getSqueezeVisionTurning() const { return _squeezeVisionTurning; }
65  void setSqueezeVisionTurning(bool value) { _squeezeVisionTurning = value; }
66 
67 private:
68  Setting::Handle<bool> _visionSqueezeEnabledSetting {"visionSqueezeEnabled", false};
69  Setting::Handle<float> _visionSqueezeRatioXSetting {"visionSqueezeRatioX", 0.0f};
70  Setting::Handle<float> _visionSqueezeRatioYSetting {"visionSqueezeRatioY", 0.0f};
71  Setting::Handle<float> _visionSqueezeUnSqueezeDelaySetting {"visionSqueezeUnSqueezeDelay",
72  DEFAULT_VISION_SQUEEZE_UNSQUEEZE_DELAY};
73  Setting::Handle<float> _visionSqueezeUnSqueezeSpeedSetting {"visionSqueezeUnSqueezeSpeed",
74  DEFAULT_VISION_SQUEEZE_UNSQUEEZE_SPEED};
75  Setting::Handle<float> _visionSqueezeTransitionSetting {"visionSqueezeTransition", DEFAULT_VISION_SQUEEZE_TRANSITION};
76  Setting::Handle<float> _visionSqueezePerEyeSetting {"visionSqueezePerEye", DEFAULT_VISION_SQUEEZE_PER_EYE};
77  Setting::Handle<float> _visionSqueezeGroundPlaneYSetting {"visionSqueezeGroundPlaneY",
78  DEFAULT_VISION_SQUEEZE_GROUND_PLANE_Y};
79  Setting::Handle<float> _visionSqueezeSpotlightSizeSetting {"visionSqueezeSpotlightSize",
80  DEFAULT_VISION_SQUEEZE_SPOTLIGHT_SIZE};
81  Setting::Handle<float> _visionSqueezeTurningXFactorSetting {"visionSqueezeTurningXFactor",
82  DEFAULT_VISION_SQUEEZE_TURNING_X_FACTOR};
83  Setting::Handle<float> _visionSqueezeTurningYFactorSetting {"visionSqueezeTurningYFactor",
84  DEFAULT_VISION_SQUEEZE_TURNING_Y_FACTOR};
85 
86 
87  // these are readable and writable from the scripting interface (on a different thread), so make them atomic
88  std::atomic<bool> _visionSqueezeEnabled { false };
89  std::atomic<float> _visionSqueezeRatioX { 0.0f };
90  std::atomic<float> _visionSqueezeRatioY { 0.0f };
91  std::atomic<float> _visionSqueezeUnSqueezeDelay { DEFAULT_VISION_SQUEEZE_UNSQUEEZE_DELAY }; // seconds
92  std::atomic<float> _visionSqueezeUnSqueezeSpeed { DEFAULT_VISION_SQUEEZE_UNSQUEEZE_SPEED };
93  std::atomic<float> _visionSqueezeTransition { DEFAULT_VISION_SQUEEZE_TRANSITION };
94  std::atomic<int> _visionSqueezePerEye { DEFAULT_VISION_SQUEEZE_PER_EYE };
95  std::atomic<float> _visionSqueezeGroundPlaneY { DEFAULT_VISION_SQUEEZE_GROUND_PLANE_Y };
96  std::atomic<float> _visionSqueezeSpotlightSize { DEFAULT_VISION_SQUEEZE_SPOTLIGHT_SIZE };
97  std::atomic<float> _visionSqueezeTurningXFactor { DEFAULT_VISION_SQUEEZE_TURNING_X_FACTOR };
98  std::atomic<float> _visionSqueezeTurningYFactor { DEFAULT_VISION_SQUEEZE_TURNING_Y_FACTOR };
99 
100  bool _squeezeVision { false };
101  bool _squeezeVisionTurning { false };
102 
103  float _visionSqueezeLockout { 0.0 };
104  glm::vec3 _prevTranslation;
105  glm::quat _prevRotation;
106 };
107 
108 #endif // hifi_VisionSqueeze_h