Commit a79a0ff7 authored by Jan Möbius's avatar Jan Möbius

Implemented Vectortype scripting functions add,multiply an sub.

git-svn-id: http://www.openflipper.org/svnrepo/OpenFlipper/branches/Free@14816 383ad7c9-94d9-4d36-a494-682f7c89f535
parent 5095c836
......@@ -38,6 +38,22 @@ TODO: OpenFlipper Scripting and examples.
print(datacontrol.dataType(object))
\endcode
\section scripting_vectortype Vector data type
The vector data type is corresponging to the Vec3d type in C++. It does not support all
of its operations yet. The implementation of the scripting type is done in prototypeVec3d.
You can use the following functions:
\code
var vec = Vector(1,2,3)
var vec2 = Vector(10,20,30)
vec.multiply(0.5) // Multiply vec with 0.5
vec.add(vec2) // Add vec2 to vec
vec.sub(vec2) // Subtract vec2 from vec
print(vec) // Output the current value: 0.5,1,1.5
\endcode
\section scripting_examples Scripting Examples
\subsection scripting_examples_qstringlist Iterating over a QStringList
......
......@@ -49,12 +49,14 @@
// Description:
//
//
// Author: Jan Moebius <jan_moebius@web.de>, (C) 2007
// Author: Jan Möbius <moebius@cs.rwth-aachen.de>, (C) 2007
//
#define PROTOTYPEVEC3D_C
#include "prototypeVec3d.hh"
#include <iostream>
prototypeVec3d::prototypeVec3d(QObject *parent ) :
QObject(parent)
......@@ -69,3 +71,21 @@ QString prototypeVec3d::toString() const {
thisObject().property("z").toString() + " )";
}
void prototypeVec3d::multiply(QScriptValue _scalar) {
thisObject().setProperty("x", QScriptValue(thisObject().property("x").toNumber() * _scalar.toNumber()));
thisObject().setProperty("y", QScriptValue(thisObject().property("y").toNumber() * _scalar.toNumber()));
thisObject().setProperty("z", QScriptValue(thisObject().property("z").toNumber() * _scalar.toNumber()));
}
void prototypeVec3d::add(QScriptValue _vector) {
thisObject().setProperty("x", QScriptValue(_vector.property("x").toNumber() + thisObject().property("x").toNumber()));
thisObject().setProperty("y", QScriptValue(_vector.property("y").toNumber() + thisObject().property("y").toNumber()));
thisObject().setProperty("z", QScriptValue(_vector.property("z").toNumber() + thisObject().property("z").toNumber()));
}
void prototypeVec3d::sub(QScriptValue _vector) {
thisObject().setProperty("x", QScriptValue(thisObject().property("x").toNumber() - _vector.property("x").toNumber()));
thisObject().setProperty("y", QScriptValue(thisObject().property("y").toNumber() - _vector.property("y").toNumber()));
thisObject().setProperty("z", QScriptValue(thisObject().property("z").toNumber() - _vector.property("z").toNumber()));
}
......@@ -49,7 +49,7 @@
// Description:
//
//
// Author: Jan Moebius <jan_moebius@web.de>, (C) 2007
// Author: Jan Möbius <moebius@cs.rwth-aachen.de>, (C) 2007
//
#ifndef PROTOTYPEVEC3D_HH
......@@ -66,6 +66,16 @@ class prototypeVec3d : public QObject , public QScriptable
public:
prototypeVec3d(QObject *parent = 0);
public slots:
// Multiplies the given vector with the scalar
void multiply(QScriptValue _scalar);
// Adds another vector to this vector
void add(QScriptValue _vector);
// Subtracts another vector from this vector
void sub(QScriptValue _vector);
public Q_SLOTS:
QString toString() const;
......@@ -73,3 +83,4 @@ class prototypeVec3d : public QObject , public QScriptable
#endif // PROTOTYPEVEC3D_HH
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment