Commit 40077bc9 authored by Jan Möbius's avatar Jan Möbius

Marlin: fixed scripting conversion for matrix and vector in core

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@9559 383ad7c9-94d9-4d36-a494-682f7c89f535
parent f92ba86f
......@@ -69,9 +69,41 @@ QScriptValue toScriptValueMatrix4x4(QScriptEngine *engine, const Matrix4x4 &s)
void fromScriptValueMatrix4x4(const QScriptValue &obj, Matrix4x4 &s)
{
for ( uint i = 0 ; i < 4 ; ++i )
for ( uint j = 0 ; j < 4 ; ++j )
s(i,j) = obj.property(QString::number(i) + QString::number(j)).toNumber();
if (obj.isObject()) {
for ( uint i = 0 ; i < 4 ; ++i )
for ( uint j = 0 ; j < 4 ; ++j )
s(i,j) = obj.property(QString::number(i) + QString::number(j)).toNumber();
return;
}
QString _from = obj.toString();
if (_from.startsWith ("Matrix4x4 ("))
_from.remove (0, 11);
else if (_from.startsWith ("Matrix4x4 : ("))
_from.remove (0, 14);
if (_from.endsWith (")"))
_from.remove (_from.length () - 1, 1);
QStringList sl = _from.split (',');
float v[16];
bool ok = true;
if (sl.length () == 16)
{
for (int i = 0; i < 16 && ok; i++)
v[i] = sl[i].toFloat (&ok);
if (ok)
for (int i = 0; i < 16; i++)
s(i/4,i%4) = v[i];
else
{
for (int i = 0; i < 16; i++)
s(i/4,i%4) = 0;
std::cerr << "String to Matrix4x4 conversion failed!" << std::endl;
}
}
}
QScriptValue createMatrix4x4(QScriptContext *context, QScriptEngine *engine)
......
......@@ -69,9 +69,39 @@ QScriptValue toScriptValueVector(QScriptEngine *engine, const Vector &s)
void fromScriptValueVector(const QScriptValue &obj, Vector &s)
{
s[0] = obj.property("x").toNumber();
s[1] = obj.property("y").toNumber();
s[2] = obj.property("z").toNumber();
if (obj.isObject()) {
s[0] = obj.property("x").toNumber();
s[1] = obj.property("y").toNumber();
s[2] = obj.property("z").toNumber();
return;
}
QString _from = obj.toString();
if (_from.startsWith ("Vector ("))
_from.remove (0, 8);
else if (_from.startsWith ("Vector : ( "))
_from.remove (0, 11);
if (_from.endsWith (")"))
_from.remove (_from.length () - 1, 1);
QStringList sl = _from.split (',');
float v[3];
bool ok = true;
if (sl.length () == 3) {
for (int i = 0; i < 3 && ok; i++)
v[i] = sl[i].toFloat (&ok);
if (ok)
for (int i = 0; i < 3; i++)
s[i] = v[i];
else {
for (int i = 0; i < 3; i++)
s[i] = 0;
std::cerr << "String to Vec3D conversion failed!" << std::endl;
}
}
}
QScriptValue createVector(QScriptContext *context, QScriptEngine *engine)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment