61 #include "vec3dWrapper.hh"
67 QScriptValue toScriptValueVector(QScriptEngine *engine,
const Vector &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]));
77 void fromScriptValueVector(
const QScriptValue &obj,
Vector &s)
80 s[0] = obj.property(
"x").toNumber();
81 s[1] = obj.property(
"y").toNumber();
82 s[2] = obj.property(
"z").toNumber();
86 QString _from = obj.toString();
87 if (_from.startsWith (
"Vector ("))
89 else if (_from.startsWith (
"Vector : ( "))
91 if (_from.endsWith (
")"))
92 _from.remove (_from.length () - 1, 1);
94 QStringList sl = _from.split (
',');
99 if (sl.length () == 3) {
100 for (
int i = 0; i < 3 && ok; i++)
101 v[i] = sl[i].toFloat (&ok);
104 for (
int i = 0; i < 3; i++)
107 for (
int i = 0; i < 3; i++)
109 std::cerr <<
"String to Vec3D conversion failed!" << std::endl;
114 QScriptValue createVector(QScriptContext *context, QScriptEngine *engine)
118 QScriptValue callee = context->callee();
122 if (context->argumentCount() == 3) {
123 s[0] = context->argument(0).toNumber();
124 s[1] = context->argument(1).toNumber();
125 s[2] = context->argument(2).toNumber();
132 return engine->toScriptValue(s);
135 QScriptValue VectorToString(QScriptContext *context, QScriptEngine *engine)
137 QString result =
"Vector : ( " +
138 context->thisObject().property(
"x").toString() +
"," +
139 context->thisObject().property(
"y").toString() +
"," +
140 context->thisObject().property(
"z").toString() +
" )";
141 return QScriptValue(engine, result);