56 #include "matrix4x4Wrapper.hh" 62 QScriptValue toScriptValueMatrix4x4(QScriptEngine *engine,
const Matrix4x4 &s)
64 QScriptValue obj = engine->newObject();
65 for ( uint i = 0 ; i < 4 ; ++i )
66 for ( uint j = 0 ; j < 4 ; ++j )
67 obj.setProperty(QString::number(i) + QString::number(j),QScriptValue(engine, s(i,j)) );
71 void fromScriptValueMatrix4x4(
const QScriptValue &obj,
Matrix4x4 &s)
74 for ( uint i = 0 ; i < 4 ; ++i )
75 for ( uint j = 0 ; j < 4 ; ++j )
76 s(i,j) = obj.property(QString::number(i) + QString::number(j)).toNumber();
80 QString _from = obj.toString();
81 if (_from.startsWith (
"Matrix4x4 ("))
83 else if (_from.startsWith (
"Matrix4x4 : ("))
85 if (_from.endsWith (
")"))
86 _from.remove (_from.length () - 1, 1);
88 QStringList sl = _from.split (
',');
93 if (sl.length () == 16)
95 for (
int i = 0; i < 16 && ok; i++)
96 v[i] = sl[i].toFloat (&ok);
99 for (
int i = 0; i < 16; i++)
103 for (
int i = 0; i < 16; i++)
105 std::cerr <<
"String to Matrix4x4 conversion failed!" << std::endl;
110 QScriptValue createMatrix4x4(QScriptContext *context, QScriptEngine *engine)
114 QScriptValue callee = context->callee();
118 if (context->argumentCount() == 16) {
119 for ( uint i = 0 ; i < 4 ; ++i )
120 for ( uint j = 0 ; j < 4 ; ++j )
121 s(i,j) = context->argument(i*4+j).toNumber();
123 for ( uint i = 0 ; i < 4 ; ++i )
124 for ( uint j = 0 ; j < 4 ; ++j )
128 return engine->toScriptValue(s);
131 QScriptValue Matrix4x4ToString(QScriptContext *context, QScriptEngine *engine)
133 QString result =
"Matrix4x4 : ( ";
135 for ( uint i = 0 ; i < 4 ; ++i )
136 for ( uint j = 0 ; j < 4 ; ++j ) {
137 if ( i == 3 && j == 3 )
139 result = result + context->thisObject().property(QString::number(i) + QString::number(j)).toString() +
" , ";
142 result = result + context->thisObject().property(
"33").toString() +
" ) ";
144 return QScriptValue(engine, result);