55 #include "vec3dWrapper.hh" 61 QScriptValue toScriptValueVector(QScriptEngine *engine,
const Vector &s)
63 QScriptValue obj = engine->newObject();
64 obj.setProperty(
"x", QScriptValue(engine, s[0]));
65 obj.setProperty(
"y", QScriptValue(engine, s[1]));
66 obj.setProperty(
"z", QScriptValue(engine, s[2]));
71 void fromScriptValueVector(
const QScriptValue &obj,
Vector &s)
74 s[0] = obj.property(
"x").toNumber();
75 s[1] = obj.property(
"y").toNumber();
76 s[2] = obj.property(
"z").toNumber();
80 QString _from = obj.toString();
81 if (_from.startsWith (
"Vector ("))
83 else if (_from.startsWith (
"Vector : ( "))
85 if (_from.endsWith (
")"))
86 _from.remove (_from.length () - 1, 1);
88 QStringList sl = _from.split (
',');
93 if (sl.length () == 3) {
94 for (
int i = 0; i < 3 && ok; i++)
95 v[i] = sl[i].toFloat (&ok);
98 for (
int i = 0; i < 3; i++)
101 for (
int i = 0; i < 3; i++)
103 std::cerr <<
"String to Vec3D conversion failed!" << std::endl;
108 QScriptValue createVector(QScriptContext *context, QScriptEngine *engine)
112 QScriptValue callee = context->callee();
116 if (context->argumentCount() == 3) {
117 s[0] = context->argument(0).toNumber();
118 s[1] = context->argument(1).toNumber();
119 s[2] = context->argument(2).toNumber();
126 return engine->toScriptValue(s);
129 QScriptValue VectorToString(QScriptContext *context, QScriptEngine *engine)
131 QString result =
"Vector : ( " +
132 context->thisObject().property(
"x").toString() +
"," +
133 context->thisObject().property(
"y").toString() +
"," +
134 context->thisObject().property(
"z").toString() +
" )";
135 return QScriptValue(engine, result);