mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge pull request #8995 from AndrewMeadows/avoid-zero-quaternion
normalize quaternions submitted to C++ from JS
This commit is contained in:
commit
2684aed523
1 changed files with 16 additions and 0 deletions
|
@ -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();
|
||||
|
|
Loading…
Reference in a new issue