From 1ae91bd8a992d47c9424cbe5c352a1a73b700d92 Mon Sep 17 00:00:00 2001 From: Giulio Camuffo Date: Sun, 18 Sep 2011 19:14:25 +0200 Subject: [PATCH] MATH: Make some global functions static function members. --- math/vector.h | 10 +++++----- math/vector3d.h | 33 +++++++++++++++++---------------- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/math/vector.h b/math/vector.h index 77e8edd7801..a0596076d8a 100644 --- a/math/vector.h +++ b/math/vector.h @@ -46,6 +46,11 @@ public: inline void setValue(int i, float val) { value(i) = val; } inline float getValue(int i) const { return value(i); } + template + inline static float dotProduct(const Vector(d) &v1, const Vector(d) &v2) { + return v1.getDotProduct(v2); + } + protected: MatrixType() : MatrixBase() { } MatrixType(float *data) : MatrixBase(data) { } @@ -98,11 +103,6 @@ float MatrixType::getDotProduct(const Vector(dim) &v) const { return result; } -template -inline float dot(const Vector(dim) &v1, const Vector(dim) &v2) { - return v1.getDotProduct(v2); -} - } template diff --git a/math/vector3d.h b/math/vector3d.h index 0c1c1eb9e56..b0d39f6d0fc 100644 --- a/math/vector3d.h +++ b/math/vector3d.h @@ -33,6 +33,8 @@ namespace Math { +typedef Matrix<3, 1> Vector3d; + template<> class Matrix<3, 1> : public MatrixType<3, 1> { public: @@ -52,24 +54,23 @@ public: // Get the angle a vector is around the unit circle // (ignores z-component) Angle unitCircleAngle() const; + + inline static Vector3d crossProduct(const Vector3d& v1, const Vector3d& v2) { + return Vector3d(v1.y() * v2.z() - v1.z() * v2.y(), + v1.z() * v2.x() - v1.x() * v2.z(), + v1.x() * v2.y() - v1.y() * v2.x()); + } + + inline static Angle angle(const Vector3d& v1, const Vector3d& v2) { + return Angle::arcCosine(dotProduct(v1, v2) / (v1.getMagnitude() * v2.getMagnitude())); + } + + inline static Vector3d get_vector3d(const char *data) { + return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8)); + } + }; -typedef Matrix<3, 1> Vector3d; - -inline Vector3d cross(const Vector3d& v1, const Vector3d& v2) { - return Vector3d(v1.y() * v2.z() - v1.z() * v2.y(), - v1.z() * v2.x() - v1.x() * v2.z(), - v1.x() * v2.y() - v1.y() * v2.x()); -} - -inline Angle angle(const Vector3d& v1, const Vector3d& v2) { - return Angle::arcCosine(dot(v1, v2) / (v1.getMagnitude() * v2.getMagnitude())); -} - -inline Vector3d get_vector3d(const char *data) { - return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8)); -} - } // end of namespace Math #endif