14 #include <GLMHelpers.h>
15 #include <SharedUtil.h>
18 const float EYE_EAR_GAP = 0.08f;
22 class Head :
public HeadData {
24 explicit Head(Avatar* owningAvatar);
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; }
35 glm::quat getFinalOrientationInLocalFrame()
const;
38 glm::quat getFinalOrientationInWorldFrame()
const;
40 void setCorrectedLookAtPosition(
const glm::vec3& correctedLookAtPosition);
41 glm::vec3 getCorrectedLookAtPosition();
42 void clearCorrectedLookAtPosition() { _isLookingAtMe =
false; }
44 quint64 getLookingAtMeStarted() {
return _lookingAtMeStarted; }
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; }
54 glm::quat getEyeRotation(
const glm::vec3& eyePosition)
const;
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); }
62 bool getReturnToCenter()
const {
return _returnHeadToCenter; }
63 float getAverageLoudness()
const {
return _averageLoudness; }
65 void setDeltaPitch(
float pitch) { _deltaPitch = pitch; }
66 float getDeltaPitch()
const {
return _deltaPitch; }
68 void setDeltaYaw(
float yaw) { _deltaYaw = yaw; }
69 float getDeltaYaw()
const {
return _deltaYaw; }
71 void setDeltaRoll(
float roll) { _deltaRoll = roll; }
72 float getDeltaRoll()
const {
return _deltaRoll; }
74 virtual float getFinalPitch()
const override;
75 virtual float getFinalYaw()
const override;
76 virtual float getFinalRoll()
const override;
78 void relax(
float deltaTime);
80 float getTimeWithoutTalking()
const {
return _timeWithoutTalking; }
82 virtual void setLookAtPosition(
const glm::vec3& lookAtPosition)
override;
83 void updateEyeLookAt();
88 Head& operator= (
const Head&);
90 bool _returnHeadToCenter {
false };
93 glm::vec3 _leftEyePosition;
94 glm::vec3 _rightEyePosition;
95 glm::vec3 _eyePosition;
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 };
109 glm::vec3 _saccadeTarget;
110 float _leftEyeBlinkVelocity { 0.0f };
111 float _rightEyeBlinkVelocity { 0.0f };
112 float _timeWithoutTalking { 0.0f };
115 float _deltaPitch { 0.0f };
116 float _deltaYaw { 0.0f };
117 float _deltaRoll { 0.0f };
119 bool _isCameraMoving {
false };
120 bool _isLookingAtMe {
false };
121 quint64 _lookingAtMeStarted { 0 };
122 quint64 _wasLastLookingAtMe { 0 };
124 glm::vec3 _correctedLookAtPosition;
126 int _leftEyeLookAtID;
127 int _rightEyeLookAtID;
129 glm::vec3 _requestLookAtPosition;
130 bool _forceBlinkToRetarget {
false };
131 bool _isEyeLookAtUpdated {
false };
134 void calculateMouthShapes(
float timeRatio);
135 void applyEyelidOffset(glm::quat headOrientation);