mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 01:56:54 +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.
|
// 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)) {
|
if (json.contains(JSON_AVATAR_HEAD)) {
|
||||||
auto avatarOrientation = getOrientation();
|
|
||||||
if (!_headData) {
|
if (!_headData) {
|
||||||
_headData = new HeadData(this);
|
_headData = new HeadData(this);
|
||||||
}
|
}
|
||||||
_headData->fromJson(json[JSON_AVATAR_HEAD].toObject());
|
_headData->fromJson(json[JSON_AVATAR_HEAD].toObject());
|
||||||
setOrientation(avatarOrientation);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains(JSON_AVATAR_SCALE)) {
|
if (json.contains(JSON_AVATAR_SCALE)) {
|
||||||
|
|
|
@ -52,6 +52,13 @@ glm::quat HeadData::getOrientation() const {
|
||||||
return _owningAvatar->getOrientation() * getRawOrientation();
|
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) {
|
void HeadData::setOrientation(const glm::quat& orientation) {
|
||||||
// rotate body about vertical axis
|
// rotate body about vertical axis
|
||||||
|
@ -61,10 +68,7 @@ void HeadData::setOrientation(const glm::quat& orientation) {
|
||||||
_owningAvatar->setOrientation(bodyOrientation);
|
_owningAvatar->setOrientation(bodyOrientation);
|
||||||
|
|
||||||
// the rest goes to the head
|
// the rest goes to the head
|
||||||
glm::vec3 eulers = glm::degrees(safeEulerAngles(glm::inverse(bodyOrientation) * orientation));
|
setHeadOrientation(orientation);
|
||||||
_basePitch = eulers.x;
|
|
||||||
_baseYaw = eulers.y;
|
|
||||||
_baseRoll = eulers.z;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Lazily construct a lookup map from the blendshapes
|
//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)) {
|
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
|
// privatize copy ctor and assignment operator so copies of this object cannot be made
|
||||||
HeadData(const HeadData&);
|
HeadData(const HeadData&);
|
||||||
HeadData& operator= (const HeadData&);
|
HeadData& operator= (const HeadData&);
|
||||||
|
|
||||||
|
void setHeadOrientation(const glm::quat& orientation);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_HeadData_h
|
#endif // hifi_HeadData_h
|
||||||
|
|
Loading…
Reference in a new issue