52 #include "vec4dWrapper.hh" 58 QScriptValue toScriptValueVector4(QScriptEngine *engine,
const Vector4 &s)
60 QScriptValue obj = engine->newObject();
61 obj.setProperty(
"x", QScriptValue(engine, s[0]));
62 obj.setProperty(
"y", QScriptValue(engine, s[1]));
63 obj.setProperty(
"z", QScriptValue(engine, s[2]));
64 obj.setProperty(
"w", QScriptValue(engine, s[3]));
68 void fromScriptValueVector4(
const QScriptValue &obj,
Vector4 &s)
71 s[0] = obj.property(
"x").toNumber();
72 s[1] = obj.property(
"y").toNumber();
73 s[2] = obj.property(
"z").toNumber();
74 s[3] = obj.property(
"w").toNumber();
78 QString _from = obj.toString();
79 if (_from.startsWith (
"Vector4 ("))
81 else if (_from.startsWith (
"Vector4 : ( "))
83 if (_from.endsWith (
")"))
84 _from.remove (_from.length () - 1, 1);
86 QStringList sl = _from.split (
',');
91 if (sl.length () == 4) {
92 for (
int i = 0; i < 4 && ok; i++)
93 v[i] = sl[i].toFloat (&ok);
96 for (
int i = 0; i < 4; i++)
99 for (
int i = 0; i < 4; i++)
101 std::cerr <<
"String to Vec4D conversion failed!" << std::endl;
106 QScriptValue createVector4(QScriptContext *context, QScriptEngine *engine)
110 QScriptValue callee = context->callee();
114 if (context->argumentCount() == 4) {
115 s[0] = context->argument(0).toNumber();
116 s[1] = context->argument(1).toNumber();
117 s[2] = context->argument(2).toNumber();
118 s[3] = context->argument(3).toNumber();
126 return engine->toScriptValue(s);
129 QScriptValue Vector4ToString(QScriptContext *context, QScriptEngine *engine)
131 QString result =
"Vector4 : ( " +
132 context->thisObject().property(
"x").toString() +
"," +
133 context->thisObject().property(
"y").toString() +
"," +
134 context->thisObject().property(
"z").toString() +
","+
135 context->thisObject().property(
"w").toString() +
" )";
136 return QScriptValue(engine, result);