mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
normalize quaternions submitted from scriptland
This commit is contained in:
parent
388c1c8efe
commit
757ec5fff4
1 changed files with 17 additions and 1 deletions
|
@ -17,7 +17,7 @@
|
|||
#include <QtGui/QVector2D>
|
||||
#include <QtGui/QVector3D>
|
||||
#include <QtGui/QQuaternion>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <QAbstractSocket>
|
||||
|
||||
#include "RegisteredMetaTypes.h"
|
||||
|
@ -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 length2 = glm::length2(quat);
|
||||
if (length2 > FLT_EPSILON) {
|
||||
quat /= sqrtf(length2);
|
||||
} 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 length2 = glm::length2(q);
|
||||
if (length2 > FLT_EPSILON) {
|
||||
q /= sqrtf(length2);
|
||||
} else {
|
||||
q = glm::quat();
|
||||
}
|
||||
isValid = true;
|
||||
} else {
|
||||
auto map = object.toMap();
|
||||
|
|
Loading…
Reference in a new issue