61 #include "vec4dWrapper.hh"
67 QScriptValue toScriptValueVector4(QScriptEngine *engine,
const Vector4 &s)
69 QScriptValue obj = engine->newObject();
70 obj.setProperty(
"x", QScriptValue(engine, s[0]));
71 obj.setProperty(
"y", QScriptValue(engine, s[1]));
72 obj.setProperty(
"z", QScriptValue(engine, s[2]));
73 obj.setProperty(
"w", QScriptValue(engine, s[3]));
77 void fromScriptValueVector4(
const QScriptValue &obj,
Vector4 &s)
80 s[0] = obj.property(
"x").toNumber();
81 s[1] = obj.property(
"y").toNumber();
82 s[2] = obj.property(
"z").toNumber();
83 s[3] = obj.property(
"w").toNumber();
87 QString _from = obj.toString();
88 if (_from.startsWith (
"Vector4 ("))
90 else if (_from.startsWith (
"Vector4 : ( "))
92 if (_from.endsWith (
")"))
93 _from.remove (_from.length () - 1, 1);
95 QStringList sl = _from.split (
',');
100 if (sl.length () == 4) {
101 for (
int i = 0; i < 4 && ok; i++)
102 v[i] = sl[i].toFloat (&ok);
105 for (
int i = 0; i < 4; i++)
108 for (
int i = 0; i < 4; i++)
110 std::cerr <<
"String to Vec4D conversion failed!" << std::endl;
115 QScriptValue createVector4(QScriptContext *context, QScriptEngine *engine)
119 QScriptValue callee = context->callee();
123 if (context->argumentCount() == 4) {
124 s[0] = context->argument(0).toNumber();
125 s[1] = context->argument(1).toNumber();
126 s[2] = context->argument(2).toNumber();
127 s[3] = context->argument(3).toNumber();
135 return engine->toScriptValue(s);
138 QScriptValue Vector4ToString(QScriptContext *context, QScriptEngine *engine)
140 QString result =
"Vector4 : ( " +
141 context->thisObject().property(
"x").toString() +
"," +
142 context->thisObject().property(
"y").toString() +
"," +
143 context->thisObject().property(
"z").toString() +
","+
144 context->thisObject().property(
"w").toString() +
" )";
145 return QScriptValue(engine, result);