mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-29 19:22:57 +02:00
add checks for NaN
This commit is contained in:
parent
014802fd45
commit
71440dfbc5
1 changed files with 23 additions and 11 deletions
|
@ -127,21 +127,21 @@ glm::vec3 EntityActionInterface::extractVec3Argument(QString objectName, QVarian
|
||||||
qDebug() << objectName << "requires argument:" << argumentName;
|
qDebug() << objectName << "requires argument:" << argumentName;
|
||||||
}
|
}
|
||||||
ok = false;
|
ok = false;
|
||||||
return glm::vec3();
|
return glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant resultV = arguments[argumentName];
|
QVariant resultV = arguments[argumentName];
|
||||||
if (resultV.type() != (QVariant::Type) QMetaType::QVariantMap) {
|
if (resultV.type() != (QVariant::Type) QMetaType::QVariantMap) {
|
||||||
qDebug() << objectName << "argument" << argumentName << "must be a map";
|
qDebug() << objectName << "argument" << argumentName << "must be a map";
|
||||||
ok = false;
|
ok = false;
|
||||||
return glm::vec3();
|
return glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap resultVM = resultV.toMap();
|
QVariantMap resultVM = resultV.toMap();
|
||||||
if (!resultVM.contains("x") || !resultVM.contains("y") || !resultVM.contains("z")) {
|
if (!resultVM.contains("x") || !resultVM.contains("y") || !resultVM.contains("z")) {
|
||||||
qDebug() << objectName << "argument" << argumentName << "must be a map with keys of x, y, z";
|
qDebug() << objectName << "argument" << argumentName << "must be a map with keys: x, y, z";
|
||||||
ok = false;
|
ok = false;
|
||||||
return glm::vec3();
|
return glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant xV = resultVM["x"];
|
QVariant xV = resultVM["x"];
|
||||||
|
@ -155,9 +155,15 @@ glm::vec3 EntityActionInterface::extractVec3Argument(QString objectName, QVarian
|
||||||
float y = yV.toFloat(&yOk);
|
float y = yV.toFloat(&yOk);
|
||||||
float z = zV.toFloat(&zOk);
|
float z = zV.toFloat(&zOk);
|
||||||
if (!xOk || !yOk || !zOk) {
|
if (!xOk || !yOk || !zOk) {
|
||||||
qDebug() << objectName << "argument" << argumentName << "must be a map with keys of x, y, z and values of type float.";
|
qDebug() << objectName << "argument" << argumentName << "must be a map with keys: x, y, and z of type float.";
|
||||||
ok = false;
|
ok = false;
|
||||||
return glm::vec3();
|
return glm::vec3(0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (x != x || y != y || z != z) {
|
||||||
|
// at least one of the values is NaN
|
||||||
|
ok = false;
|
||||||
|
return glm::vec3(0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
return glm::vec3(x, y, z);
|
return glm::vec3(x, y, z);
|
||||||
|
@ -181,8 +187,8 @@ glm::quat EntityActionInterface::extractQuatArgument(QString objectName, QVarian
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariantMap resultVM = resultV.toMap();
|
QVariantMap resultVM = resultV.toMap();
|
||||||
if (!resultVM.contains("x") || !resultVM.contains("y") || !resultVM.contains("z")) {
|
if (!resultVM.contains("x") || !resultVM.contains("y") || !resultVM.contains("z") || !resultVM.contains("w")) {
|
||||||
qDebug() << objectName << "argument" << argumentName << "must be a map with keys of x, y, z";
|
qDebug() << objectName << "argument" << argumentName << "must be a map with keys: x, y, z, and w";
|
||||||
ok = false;
|
ok = false;
|
||||||
return glm::quat();
|
return glm::quat();
|
||||||
}
|
}
|
||||||
|
@ -202,12 +208,18 @@ glm::quat EntityActionInterface::extractQuatArgument(QString objectName, QVarian
|
||||||
float w = wV.toFloat(&wOk);
|
float w = wV.toFloat(&wOk);
|
||||||
if (!xOk || !yOk || !zOk || !wOk) {
|
if (!xOk || !yOk || !zOk || !wOk) {
|
||||||
qDebug() << objectName << "argument" << argumentName
|
qDebug() << objectName << "argument" << argumentName
|
||||||
<< "must be a map with keys of x, y, z, w and values of type float.";
|
<< "must be a map with keys: x, y, z, and w of type float.";
|
||||||
ok = false;
|
ok = false;
|
||||||
return glm::quat();
|
return glm::quat();
|
||||||
}
|
}
|
||||||
|
|
||||||
return glm::quat(w, x, y, z);
|
if (x != x || y != y || z != z || w != w) {
|
||||||
|
// at least one of the components is NaN!
|
||||||
|
ok = false;
|
||||||
|
return glm::quat();
|
||||||
|
}
|
||||||
|
|
||||||
|
return glm::normalize(glm::quat(w, x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
float EntityActionInterface::extractFloatArgument(QString objectName, QVariantMap arguments,
|
float EntityActionInterface::extractFloatArgument(QString objectName, QVariantMap arguments,
|
||||||
|
@ -224,7 +236,7 @@ float EntityActionInterface::extractFloatArgument(QString objectName, QVariantMa
|
||||||
bool vOk = true;
|
bool vOk = true;
|
||||||
float v = vV.toFloat(&vOk);
|
float v = vV.toFloat(&vOk);
|
||||||
|
|
||||||
if (!vOk) {
|
if (!vOk || v != v) {
|
||||||
ok = false;
|
ok = false;
|
||||||
return 0.0f;
|
return 0.0f;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue