Merge pull request #8995 from AndrewMeadows/avoid-zero-quaternion

normalize quaternions submitted to C++ from JS
This commit is contained in:
Brad Hefta-Gaub 2016-11-04 14:34:42 -07:00 committed by GitHub
commit 2684aed523

View file

@ -263,6 +263,14 @@ void quatFromScriptValue(const QScriptValue& object, glm::quat &quat) {
quat.y = object.property("y").toVariant().toFloat();
quat.z = object.property("z").toVariant().toFloat();
quat.w = object.property("w").toVariant().toFloat();
// enforce normalized quaternion
float length = glm::length(quat);
if (length > FLT_EPSILON) {
quat /= length;
} else {
quat = glm::quat();
}
}
glm::quat quatFromVariant(const QVariant &object, bool& isValid) {
@ -273,6 +281,14 @@ glm::quat quatFromVariant(const QVariant &object, bool& isValid) {
q.y = qvec3.y();
q.z = qvec3.z();
q.w = qvec3.scalar();
// enforce normalized quaternion
float length = glm::length(q);
if (length > FLT_EPSILON) {
q /= length;
} else {
q = glm::quat();
}
isValid = true;
} else {
auto map = object.toMap();