Tidy code setting head orientation

This commit is contained in:
David Rowe 2017-05-18 13:55:06 +12:00
parent f00232ab6d
commit 26e390fa89
3 changed files with 11 additions and 9 deletions

View file

@ -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)) {

View file

@ -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]));
}
}

View file

@ -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