mirror of
https://github.com/lubosz/overte.git
synced 2025-04-16 04:53:13 +02:00
Tidy code setting head orientation
This commit is contained in:
parent
f00232ab6d
commit
26e390fa89
3 changed files with 11 additions and 9 deletions
|
@ -2078,14 +2078,11 @@ void AvatarData::fromJson(const QJsonObject& json, bool useFrameSkeleton) {
|
|||
}
|
||||
|
||||
// Do after avatar orientation because head look-at needs avatar orientation.
|
||||
// But the head setOrientation() overwrites avatar orientation so reset the correct orientation after.
|
||||
if (json.contains(JSON_AVATAR_HEAD)) {
|
||||
auto avatarOrientation = getOrientation();
|
||||
if (!_headData) {
|
||||
_headData = new HeadData(this);
|
||||
}
|
||||
_headData->fromJson(json[JSON_AVATAR_HEAD].toObject());
|
||||
setOrientation(avatarOrientation);
|
||||
}
|
||||
|
||||
if (json.contains(JSON_AVATAR_SCALE)) {
|
||||
|
|
|
@ -52,6 +52,13 @@ glm::quat HeadData::getOrientation() const {
|
|||
return _owningAvatar->getOrientation() * getRawOrientation();
|
||||
}
|
||||
|
||||
void HeadData::setHeadOrientation(const glm::quat& orientation) {
|
||||
glm::quat bodyOrientation = _owningAvatar->getOrientation();
|
||||
glm::vec3 eulers = glm::degrees(safeEulerAngles(glm::inverse(bodyOrientation) * orientation));
|
||||
_basePitch = eulers.x;
|
||||
_baseYaw = eulers.y;
|
||||
_baseRoll = eulers.z;
|
||||
}
|
||||
|
||||
void HeadData::setOrientation(const glm::quat& orientation) {
|
||||
// rotate body about vertical axis
|
||||
|
@ -61,10 +68,7 @@ void HeadData::setOrientation(const glm::quat& orientation) {
|
|||
_owningAvatar->setOrientation(bodyOrientation);
|
||||
|
||||
// the rest goes to the head
|
||||
glm::vec3 eulers = glm::degrees(safeEulerAngles(glm::inverse(bodyOrientation) * orientation));
|
||||
_basePitch = eulers.x;
|
||||
_baseYaw = eulers.y;
|
||||
_baseRoll = eulers.z;
|
||||
setHeadOrientation(orientation);
|
||||
}
|
||||
|
||||
//Lazily construct a lookup map from the blendshapes
|
||||
|
@ -180,8 +184,7 @@ void HeadData::fromJson(const QJsonObject& json) {
|
|||
}
|
||||
}
|
||||
|
||||
// Do after look-at because look-at requires original avatar orientation and setOrientation() may change the value.
|
||||
if (json.contains(JSON_AVATAR_HEAD_ROTATION)) {
|
||||
setOrientation(quatFromJsonValue(json[JSON_AVATAR_HEAD_ROTATION]));
|
||||
setHeadOrientation(quatFromJsonValue(json[JSON_AVATAR_HEAD_ROTATION]));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,6 +101,8 @@ private:
|
|||
// privatize copy ctor and assignment operator so copies of this object cannot be made
|
||||
HeadData(const HeadData&);
|
||||
HeadData& operator= (const HeadData&);
|
||||
|
||||
void setHeadOrientation(const glm::quat& orientation);
|
||||
};
|
||||
|
||||
#endif // hifi_HeadData_h
|
||||
|
|
Loading…
Reference in a new issue