62 #include "matrix4x4Wrapper.hh"
68 QScriptValue toScriptValueMatrix4x4(QScriptEngine *engine,
const Matrix4x4 &s)
70 QScriptValue obj = engine->newObject();
71 for ( uint i = 0 ; i < 4 ; ++i )
72 for ( uint j = 0 ; j < 4 ; ++j )
73 obj.setProperty(QString::number(i) + QString::number(j),QScriptValue(engine, s(i,j)) );
77 void fromScriptValueMatrix4x4(
const QScriptValue &obj,
Matrix4x4 &s)
80 for ( uint i = 0 ; i < 4 ; ++i )
81 for ( uint j = 0 ; j < 4 ; ++j )
82 s(i,j) = obj.property(QString::number(i) + QString::number(j)).toNumber();
86 QString _from = obj.toString();
87 if (_from.startsWith (
"Matrix4x4 ("))
89 else if (_from.startsWith (
"Matrix4x4 : ("))
91 if (_from.endsWith (
")"))
92 _from.remove (_from.length () - 1, 1);
94 QStringList sl = _from.split (
',');
99 if (sl.length () == 16)
101 for (
int i = 0; i < 16 && ok; i++)
102 v[i] = sl[i].toFloat (&ok);
105 for (
int i = 0; i < 16; i++)
109 for (
int i = 0; i < 16; i++)
111 std::cerr <<
"String to Matrix4x4 conversion failed!" << std::endl;
116 QScriptValue createMatrix4x4(QScriptContext *context, QScriptEngine *engine)
120 QScriptValue callee = context->callee();
124 if (context->argumentCount() == 16) {
125 for ( uint i = 0 ; i < 4 ; ++i )
126 for ( uint j = 0 ; j < 4 ; ++j )
127 s(i,j) = context->argument(i*4+j).toNumber();
129 for ( uint i = 0 ; i < 4 ; ++i )
130 for ( uint j = 0 ; j < 4 ; ++j )
134 return engine->toScriptValue(s);
137 QScriptValue Matrix4x4ToString(QScriptContext *context, QScriptEngine *engine)
139 QString result =
"Matrix4x4 : ( ";
141 for ( uint i = 0 ; i < 4 ; ++i )
142 for ( uint j = 0 ; j < 4 ; ++j ) {
143 if ( i == 3 && j == 3 )
145 result = result + context->thisObject().property(QString::number(i) + QString::number(j)).toString() +
" , ";
148 result = result + context->thisObject().property(
"33").toString() +
" ) ";
150 return QScriptValue(engine, result);