Overte C++ Documentation
Head.h
1 //
2 // Head.h
3 // interface/src/avatar
4 //
5 // Copyright 2013 High Fidelity, Inc.
6 //
7 // Distributed under the Apache License, Version 2.0.
8 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
9 //
10 
11 #ifndef hifi_Head_h
12 #define hifi_Head_h
13 
14 #include <GLMHelpers.h>
15 #include <SharedUtil.h>
16 #include <HeadData.h>
17 
18 const float EYE_EAR_GAP = 0.08f;
19 
20 class Avatar;
21 
22 class Head : public HeadData {
23 public:
24  explicit Head(Avatar* owningAvatar);
25 
26  void init();
27  void reset();
28  virtual void simulate(float deltaTime);
29  void setScale(float scale);
30  void setPosition(const glm::vec3& position) { _position = position; }
31  void setAverageLoudness(float averageLoudness) { _averageLoudness = averageLoudness; }
32  void setReturnToCenter (bool returnHeadToCenter) { _returnHeadToCenter = returnHeadToCenter; }
33 
35  glm::quat getFinalOrientationInLocalFrame() const;
36 
38  glm::quat getFinalOrientationInWorldFrame() const;
39 
40  void setCorrectedLookAtPosition(const glm::vec3& correctedLookAtPosition);
41  glm::vec3 getCorrectedLookAtPosition();
42  void clearCorrectedLookAtPosition() { _isLookingAtMe = false; }
43  bool isLookingAtMe();
44  quint64 getLookingAtMeStarted() { return _lookingAtMeStarted; }
45 
46  float getScale() const { return _scale; }
47  const glm::vec3& getPosition() const { return _position; }
48  const glm::vec3& getEyePosition() const { return _eyePosition; }
49  const glm::vec3& getSaccade() const { return _saccade; }
50  glm::vec3 getRightDirection() const { return getOrientation() * IDENTITY_RIGHT; }
51  glm::vec3 getUpDirection() const { return getOrientation() * IDENTITY_UP; }
52  glm::vec3 getForwardDirection() const { return getOrientation() * IDENTITY_FORWARD; }
53 
54  glm::quat getEyeRotation(const glm::vec3& eyePosition) const;
55 
56  const glm::vec3& getRightEyePosition() const { return _rightEyePosition; }
57  const glm::vec3& getLeftEyePosition() const { return _leftEyePosition; }
58  glm::vec3 getRightEarPosition() const { return _rightEyePosition + (getRightDirection() * EYE_EAR_GAP) + (getForwardDirection() * -EYE_EAR_GAP); }
59  glm::vec3 getLeftEarPosition() const { return _leftEyePosition + (getRightDirection() * -EYE_EAR_GAP) + (getForwardDirection() * -EYE_EAR_GAP); }
60  glm::vec3 getMouthPosition() const { return _eyePosition - getUpDirection() * glm::length(_rightEyePosition - _leftEyePosition); }
61 
62  bool getReturnToCenter() const { return _returnHeadToCenter; } // Do you want head to try to return to center (depends on interface detected)
63  float getAverageLoudness() const { return _averageLoudness; }
64 
65  void setDeltaPitch(float pitch) { _deltaPitch = pitch; }
66  float getDeltaPitch() const { return _deltaPitch; }
67 
68  void setDeltaYaw(float yaw) { _deltaYaw = yaw; }
69  float getDeltaYaw() const { return _deltaYaw; }
70 
71  void setDeltaRoll(float roll) { _deltaRoll = roll; }
72  float getDeltaRoll() const { return _deltaRoll; }
73 
74  virtual float getFinalPitch() const override;
75  virtual float getFinalYaw() const override;
76  virtual float getFinalRoll() const override;
77 
78  void relax(float deltaTime);
79 
80  float getTimeWithoutTalking() const { return _timeWithoutTalking; }
81 
82  virtual void setLookAtPosition(const glm::vec3& lookAtPosition) override;
83  void updateEyeLookAt();
84 
85 protected:
86  // disallow copies of the Head, copy of owning Avatar is disallowed too
87  Head(const Head&);
88  Head& operator= (const Head&);
89 
90  bool _returnHeadToCenter { false };
91  glm::vec3 _position;
92  glm::vec3 _rotation;
93  glm::vec3 _leftEyePosition;
94  glm::vec3 _rightEyePosition;
95  glm::vec3 _eyePosition;
96 
97  float _scale { 1.0f };
98  float _lastLoudness { 0.0f };
99  float _longTermAverageLoudness { -1.0f };
100  float _audioAttack { 0.0f };
101  float _audioJawOpen { 0.0f };
102  float _trailingAudioJawOpen { 0.0f };
103  float _mouth2 { 0.0f };
104  float _mouth3 { 0.0f };
105  float _mouth4 { 0.0f };
106  float _mouthTime { 0.0f };
107 
108  glm::vec3 _saccade;
109  glm::vec3 _saccadeTarget;
110  float _leftEyeBlinkVelocity { 0.0f };
111  float _rightEyeBlinkVelocity { 0.0f };
112  float _timeWithoutTalking { 0.0f };
113 
114  // delta angles for local head rotation (driven by hardware input)
115  float _deltaPitch { 0.0f };
116  float _deltaYaw { 0.0f };
117  float _deltaRoll { 0.0f };
118 
119  bool _isCameraMoving { false };
120  bool _isLookingAtMe { false };
121  quint64 _lookingAtMeStarted { 0 };
122  quint64 _wasLastLookingAtMe { 0 };
123 
124  glm::vec3 _correctedLookAtPosition;
125 
126  int _leftEyeLookAtID;
127  int _rightEyeLookAtID;
128 
129  glm::vec3 _requestLookAtPosition;
130  bool _forceBlinkToRetarget { false };
131  bool _isEyeLookAtUpdated { false };
132 
133  // private methods
134  void calculateMouthShapes(float timeRatio);
135  void applyEyelidOffset(glm::quat headOrientation);
136 };
137 
138 #endif // hifi_Head_h