summaryrefslogtreecommitdiffstats
path: root/kolf/vector.h
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitc90c389a8a8d9d8661e9772ec4144c5cf2039f23 (patch)
tree6d8391395bce9eaea4ad78958617edb20c6a7573 /kolf/vector.h
downloadtdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.tar.gz
tdegames-c90c389a8a8d9d8661e9772ec4144c5cf2039f23.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegames@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kolf/vector.h')
-rw-r--r--kolf/vector.h92
1 files changed, 92 insertions, 0 deletions
diff --git a/kolf/vector.h b/kolf/vector.h
new file mode 100644
index 00000000..1da7328b
--- /dev/null
+++ b/kolf/vector.h
@@ -0,0 +1,92 @@
+#ifndef KOLF_VECTOR_H
+#define KOLF_VECTOR_H
+
+#include <math.h>
+
+#include <qpoint.h>
+
+class Point
+{
+public:
+ Point(double _x, double _y)
+ {
+ x = _x;
+ y = _y;
+ }
+
+ Point()
+ {
+ x = 0;
+ y = 0;
+ }
+
+ double x;
+ double y;
+};
+
+void debugPoint(const QString &, const Point &);
+
+// This and vector.cpp by Ryan Cummings
+
+// Implements a vector in 2D
+class Vector {
+ public:
+ // Normal constructors
+ Vector(double magnitude, double direction) { _magnitude = magnitude; _direction = direction; }
+ Vector(const QPoint& source, const QPoint& dest);
+ Vector(const Point& source, const Point& dest);
+ Vector();
+
+ // Copy constructor
+ Vector(const Vector&);
+
+ // Accessors, sorta
+ double componentX() const { return (_magnitude * cos(_direction)); };
+ double componentY() const { return (_magnitude * sin(_direction)); };
+
+ // Sets individual components
+ // Wrappers around setComponents(double, double) - below
+ void setComponentX(double x);
+ void setComponentY(double y);
+
+ // Sets both components at once
+ void setComponents(double x, double y);
+
+ // Accessors
+ double magnitude() const { return _magnitude; }
+ double direction() const { return _direction; }
+ void setMagnitude(double m) { _magnitude = m; }
+ void setDirection(double d) { _direction = d; }
+
+ // Vector math
+ Vector operator+(const Vector&);
+ Vector operator-(const Vector&);
+
+ Vector& operator+=(const Vector&);
+ Vector& operator-=(const Vector&);
+
+ // Dot product
+ double operator*(const Vector&);
+
+ // Magnitude math
+ Vector operator+(double m) { return Vector(_magnitude + m, _direction); }
+ Vector operator-(double m) { return Vector(_magnitude - m, _direction); }
+ Vector operator*(double m) { return Vector(_magnitude * m, _direction); }
+ Vector operator/(double m) { return Vector(_magnitude / m, _direction); }
+
+ Vector& operator+=(double m);
+ Vector& operator-=(double m);
+ Vector& operator*=(double m);
+ Vector& operator/=(double m);
+
+ // Return the vector's equalivent on the unit circle
+ Vector unit() const { return Vector(1.0, _direction); }
+
+ protected:
+ double _magnitude;
+ double _direction;
+};
+
+void debugVector(const QString &, const Vector &);
+
+#endif