Overte C++ Documentation
HeadData.h
1 //
2 // HeadData.h
3 // libraries/avatars/src
4 //
5 // Created by Stephen Birarda on 5/20/13.
6 // Copyright 2013 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_HeadData_h
13 #define hifi_HeadData_h
14 
15 #include <iostream>
16 
17 #include <QVector>
18 
19 #include <glm/glm.hpp>
20 #include <glm/gtc/quaternion.hpp>
21 
22 #include <SharedUtil.h>
23 #include <BlendshapeConstants.h>
24 
25 // degrees
26 const float MIN_HEAD_YAW = -180.0f;
27 const float MAX_HEAD_YAW = 180.0f;
28 const float MIN_HEAD_PITCH = -60.0f;
29 const float MAX_HEAD_PITCH = 60.0f;
30 const float MIN_HEAD_ROLL = -50.0f;
31 const float MAX_HEAD_ROLL = 50.0f;
32 
33 class AvatarData;
34 class QJsonObject;
35 
36 class HeadData {
37 public:
38  explicit HeadData(AvatarData* owningAvatar);
39  virtual ~HeadData() { };
40 
41  // degrees
42  float getBaseYaw() const { return _baseYaw; }
43  void setBaseYaw(float yaw) { _baseYaw = glm::clamp(yaw, MIN_HEAD_YAW, MAX_HEAD_YAW); }
44  float getBasePitch() const { return _basePitch; }
45  void setBasePitch(float pitch) { _basePitch = glm::clamp(pitch, MIN_HEAD_PITCH, MAX_HEAD_PITCH); }
46  float getBaseRoll() const { return _baseRoll; }
47  void setBaseRoll(float roll) { _baseRoll = glm::clamp(roll, MIN_HEAD_ROLL, MAX_HEAD_ROLL); }
48 
49  virtual float getFinalYaw() const { return _baseYaw; }
50  virtual float getFinalPitch() const { return _basePitch; }
51  virtual float getFinalRoll() const { return _baseRoll; }
52  virtual glm::quat getRawOrientation() const;
53  virtual void setRawOrientation(const glm::quat& orientation);
54 
55  glm::quat getOrientation() const;
56  void setOrientation(const glm::quat& orientation);
57 
58  void setBlendshape(QString name, float val);
59  int getBlendshapeIndex(const QString& name);
60  void getBlendshapeIndices(const std::vector<QString>& blendShapeNames, std::vector<int>& indexes);
61  const QVector<float>& getBlendshapeCoefficients() const { return _blendshapeCoefficients; }
62  const QVector<float>& getSummedBlendshapeCoefficients();
63  int getNumSummedBlendshapeCoefficients() const;
64  void setBlendshapeCoefficients(const QVector<float>& blendshapeCoefficients) { _blendshapeCoefficients = blendshapeCoefficients; }
65  void clearBlendshapeCoefficients();
66 
67  const glm::vec3& getLookAtPosition() const { return _lookAtPosition; }
68  virtual void setLookAtPosition(const glm::vec3& lookAtPosition) {
69  if (_lookAtPosition != lookAtPosition) {
70  _lookAtPositionChanged = usecTimestampNow();
71  }
72  _lookAtPosition = lookAtPosition;
73  }
74  bool lookAtPositionChangedSince(quint64 time) { return _lookAtPositionChanged >= time; }
75 
76  enum ProceduralAnimationType {
77  AudioProceduralBlendshapeAnimation = 0,
78  BlinkProceduralBlendshapeAnimation,
79  LidAdjustmentProceduralBlendshapeAnimation,
80  SaccadeProceduralEyeJointAnimation,
81  ProceduralAnimaitonTypeCount,
82  };
83 
84  // called by scripts to enable or disable procedural blendshape or eye joint animations.
85  bool getProceduralAnimationFlag(ProceduralAnimationType type) const;
86  void setProceduralAnimationFlag(ProceduralAnimationType type, bool value);
87 
88  // called by c++ to suppress, i.e. temporarily disable a procedural animation.
89  bool getSuppressProceduralAnimationFlag(ProceduralAnimationType flag) const;
90  void setSuppressProceduralAnimationFlag(ProceduralAnimationType flag, bool value);
91 
92  // called by scripts to enable/disable manual adjustment of blendshapes
93  void setHasScriptedBlendshapes(bool value);
94  bool getHasScriptedBlendshapes() const;
95 
96  // called by C++ code to denote the presence of manually driven blendshapes.
97  void setHasInputDrivenBlendshapes(bool value);
98  bool getHasInputDrivenBlendshapes() const;
99 
100  friend class AvatarData;
101 
102  QJsonObject toJson() const;
103  void fromJson(const QJsonObject& json);
104 
105 protected:
106  // degrees
107  float _baseYaw;
108  float _basePitch;
109  float _baseRoll;
110 
111  glm::vec3 _lookAtPosition;
112  quint64 _lookAtPositionChanged { 0 };
113 
114  std::vector<bool> _userProceduralAnimationFlags;
115  std::vector<bool> _suppressProceduralAnimationFlags;
116 
117  bool _hasScriptedBlendshapes { false };
118  bool _hasInputDrivenBlendshapes { false };
119 
120  float _leftEyeBlink { 0.0f };
121  float _rightEyeBlink { 0.0f };
122  float _averageLoudness { 0.0f };
123  float _browAudioLift { 0.0f };
124 
125  QVector<float> _blendshapeCoefficients;
126  QVector<float> _transientBlendshapeCoefficients;
127  QVector<float> _summedBlendshapeCoefficients;
128  AvatarData* _owningAvatar;
129 
130 private:
131  Q_DISABLE_COPY(HeadData)
132 
133  void setHeadOrientation(const glm::quat& orientation);
134 };
135 
136 #endif // hifi_HeadData_h