mirror of
https://github.com/overte-org/overte.git
synced 2025-04-23 12:53:32 +02:00
* update Vec3.print, Quat.print, Mat4.print, ScriptUUID.print to work with JSConsole and HMD-friendly script log
* add test output for Quat-euler and Mat4-row/col prints
This commit is contained in:
parent
deeb9c367a
commit
f71552c648
9 changed files with 62 additions and 23 deletions
libraries/script-engine/src
scripts/developer/tests
|
@ -11,7 +11,9 @@
|
|||
|
||||
#include <QDebug>
|
||||
#include <GLMHelpers.h>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include "ScriptEngineLogging.h"
|
||||
#include "ScriptEngine.h"
|
||||
#include "Mat4.h"
|
||||
|
||||
glm::mat4 Mat4::multiply(const glm::mat4& m1, const glm::mat4& m2) const {
|
||||
|
@ -66,10 +68,12 @@ glm::vec3 Mat4::getUp(const glm::mat4& m) const {
|
|||
return glm::vec3(m[0][1], m[1][1], m[2][1]);
|
||||
}
|
||||
|
||||
void Mat4::print(const QString& label, const glm::mat4& m) const {
|
||||
qCDebug(scriptengine) << qPrintable(label) <<
|
||||
"row0 =" << m[0][0] << "," << m[1][0] << "," << m[2][0] << "," << m[3][0] <<
|
||||
"row1 =" << m[0][1] << "," << m[1][1] << "," << m[2][1] << "," << m[3][1] <<
|
||||
"row2 =" << m[0][2] << "," << m[1][2] << "," << m[2][2] << "," << m[3][2] <<
|
||||
"row3 =" << m[0][3] << "," << m[1][3] << "," << m[2][3] << "," << m[3][3];
|
||||
void Mat4::print(const QString& label, const glm::mat4& m, bool transpose) const {
|
||||
glm::mat4 out = transpose ? glm::transpose(m) : m;
|
||||
QString message = QString("%1 %2").arg(qPrintable(label));
|
||||
message = message.arg(glm::to_string(out).c_str());
|
||||
qCDebug(scriptengine) << message;
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->print(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,9 +16,10 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QtScript/QScriptable>
|
||||
|
||||
/// Scriptable Mat4 object. Used exclusively in the JavaScript API
|
||||
class Mat4 : public QObject {
|
||||
class Mat4 : public QObject, protected QScriptable {
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
|
@ -43,7 +44,7 @@ public slots:
|
|||
glm::vec3 getRight(const glm::mat4& m) const;
|
||||
glm::vec3 getUp(const glm::mat4& m) const;
|
||||
|
||||
void print(const QString& label, const glm::mat4& m) const;
|
||||
void print(const QString& label, const glm::mat4& m, bool transpose = false) const;
|
||||
};
|
||||
|
||||
#endif // hifi_Mat4_h
|
||||
|
|
|
@ -15,7 +15,9 @@
|
|||
|
||||
#include <OctreeConstants.h>
|
||||
#include <GLMHelpers.h>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
#include "ScriptEngineLogging.h"
|
||||
#include "ScriptEngine.h"
|
||||
#include "Quat.h"
|
||||
|
||||
quat Quat::normalize(const glm::quat& q) {
|
||||
|
@ -114,8 +116,17 @@ float Quat::dot(const glm::quat& q1, const glm::quat& q2) {
|
|||
return glm::dot(q1, q2);
|
||||
}
|
||||
|
||||
void Quat::print(const QString& label, const glm::quat& q) {
|
||||
qCDebug(scriptengine) << qPrintable(label) << q.x << "," << q.y << "," << q.z << "," << q.w;
|
||||
void Quat::print(const QString& label, const glm::quat& q, bool asDegrees) {
|
||||
QString message = QString("%1 %2").arg(qPrintable(label));
|
||||
if (asDegrees) {
|
||||
message = message.arg(glm::to_string(safeEulerAngles(q)).c_str());
|
||||
} else {
|
||||
message = message.arg(glm::to_string(q).c_str());
|
||||
}
|
||||
qCDebug(scriptengine) << message;
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->print(message);
|
||||
}
|
||||
}
|
||||
|
||||
bool Quat::equal(const glm::quat& q1, const glm::quat& q2) {
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
#include <QObject>
|
||||
#include <QString>
|
||||
#include <QtScript/QScriptable>
|
||||
|
||||
/**jsdoc
|
||||
* A Quaternion
|
||||
|
@ -30,7 +31,7 @@
|
|||
*/
|
||||
|
||||
/// Scriptable interface a Quaternion helper class object. Used exclusively in the JavaScript API
|
||||
class Quat : public QObject {
|
||||
class Quat : public QObject, protected QScriptable {
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
|
@ -58,7 +59,7 @@ public slots:
|
|||
glm::quat slerp(const glm::quat& q1, const glm::quat& q2, float alpha);
|
||||
glm::quat squad(const glm::quat& q1, const glm::quat& q2, const glm::quat& s1, const glm::quat& s2, float h);
|
||||
float dot(const glm::quat& q1, const glm::quat& q2);
|
||||
void print(const QString& label, const glm::quat& q);
|
||||
void print(const QString& label, const glm::quat& q, bool asDegrees = false);
|
||||
bool equal(const glm::quat& q1, const glm::quat& q2);
|
||||
glm::quat cancelOutRollAndPitch(const glm::quat& q);
|
||||
glm::quat cancelOutRoll(const glm::quat& q);
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <QDebug>
|
||||
|
||||
#include "ScriptEngineLogging.h"
|
||||
#include "ScriptEngine.h"
|
||||
#include "ScriptUUID.h"
|
||||
|
||||
QUuid ScriptUUID::fromString(const QString& s) {
|
||||
|
@ -36,6 +37,11 @@ bool ScriptUUID::isNull(const QUuid& id) {
|
|||
return id.isNull();
|
||||
}
|
||||
|
||||
void ScriptUUID::print(const QString& lable, const QUuid& id) {
|
||||
qCDebug(scriptengine) << qPrintable(lable) << id.toString();
|
||||
void ScriptUUID::print(const QString& label, const QUuid& id) {
|
||||
QString message = QString("%1 %2").arg(qPrintable(label));
|
||||
message = message.arg(id.toString());
|
||||
qCDebug(scriptengine) << message;
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->print(message);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,10 @@
|
|||
#define hifi_ScriptUUID_h
|
||||
|
||||
#include <QUuid>
|
||||
#include <QtScript/QScriptable>
|
||||
|
||||
/// Scriptable interface for a UUID helper class object. Used exclusively in the JavaScript API
|
||||
class ScriptUUID : public QObject {
|
||||
class ScriptUUID : public QObject, protected QScriptable {
|
||||
Q_OBJECT
|
||||
|
||||
public slots:
|
||||
|
@ -26,7 +27,7 @@ public slots:
|
|||
QUuid generate();
|
||||
bool isEqual(const QUuid& idA, const QUuid& idB);
|
||||
bool isNull(const QUuid& id);
|
||||
void print(const QString& lable, const QUuid& id);
|
||||
void print(const QString& label, const QUuid& id);
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptUUID_h
|
||||
|
|
|
@ -14,20 +14,26 @@
|
|||
#include <QDebug>
|
||||
|
||||
#include <GLMHelpers.h>
|
||||
#include <glm/gtx/string_cast.hpp>
|
||||
|
||||
#include "ScriptEngineLogging.h"
|
||||
#include "NumericalConstants.h"
|
||||
#include "Vec3.h"
|
||||
|
||||
#include "ScriptEngine.h"
|
||||
|
||||
float Vec3::orientedAngle(const glm::vec3& v1, const glm::vec3& v2, const glm::vec3& v3) {
|
||||
float radians = glm::orientedAngle(glm::normalize(v1), glm::normalize(v2), glm::normalize(v3));
|
||||
return glm::degrees(radians);
|
||||
}
|
||||
|
||||
|
||||
void Vec3::print(const QString& lable, const glm::vec3& v) {
|
||||
qCDebug(scriptengine) << qPrintable(lable) << v.x << "," << v.y << "," << v.z;
|
||||
void Vec3::print(const QString& label, const glm::vec3& v) {
|
||||
QString message = QString("%1 %2").arg(qPrintable(label));
|
||||
message = message.arg(glm::to_string(v).c_str());
|
||||
qCDebug(scriptengine) << message;
|
||||
if (ScriptEngine* scriptEngine = qobject_cast<ScriptEngine*>(engine())) {
|
||||
scriptEngine->print(message);
|
||||
}
|
||||
}
|
||||
|
||||
bool Vec3::withinEpsilon(const glm::vec3& v1, const glm::vec3& v2, float epsilon) {
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
#include <QtScript/QScriptable>
|
||||
|
||||
#include "GLMHelpers.h"
|
||||
|
||||
|
@ -48,7 +49,7 @@
|
|||
*/
|
||||
|
||||
/// Scriptable interface a Vec3ernion helper class object. Used exclusively in the JavaScript API
|
||||
class Vec3 : public QObject {
|
||||
class Vec3 : public QObject, protected QScriptable {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(glm::vec3 UNIT_X READ UNIT_X CONSTANT)
|
||||
Q_PROPERTY(glm::vec3 UNIT_Y READ UNIT_Y CONSTANT)
|
||||
|
|
|
@ -19,13 +19,21 @@ function main() {
|
|||
Script.errorMessage('[Script.errorMessage] hello world', '{filename}');
|
||||
|
||||
{
|
||||
// FIXME: these only show up in the application debug log
|
||||
Vec3.print('[Vec3.print]', Vec3.HALF);
|
||||
|
||||
var q = Quat.fromPitchYawRollDegrees(45, 45, 45);
|
||||
Quat.print('[Quat.print]', q);
|
||||
Quat.print('[Quat.print (euler)]', q, true);
|
||||
|
||||
var m = Mat4.createFromRotAndTrans(q, Vec3.HALF);
|
||||
Mat4.print('[Mat4.print (row major)]', m);
|
||||
function vec4(x,y,z,w) {
|
||||
return { x: x, y: y, z: z, w: w };
|
||||
}
|
||||
var m = Mat4.createFromColumns(
|
||||
vec4(1,2,3,4), vec4(5,6,7,8), vec4(9,10,11,12), vec4(13,14,15,16)
|
||||
);
|
||||
Mat4.print('[Mat4.print (col major)]', m);
|
||||
Mat4.print('[Mat4.print (row major)]', m, true);
|
||||
|
||||
Uuid.print('[Uuid.print]', Uuid.toString(0));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue