MATH: Make some global functions static function members.

This commit is contained in:
Giulio Camuffo 2011-09-18 19:14:25 +02:00
parent 59d219c955
commit 1ae91bd8a9
2 changed files with 22 additions and 21 deletions

View file

@ -46,6 +46,11 @@ public:
inline void setValue(int i, float val) { value(i) = val; } inline void setValue(int i, float val) { value(i) = val; }
inline float getValue(int i) const { return value(i); } inline float getValue(int i) const { return value(i); }
template<int d>
inline static float dotProduct(const Vector(d) &v1, const Vector(d) &v2) {
return v1.getDotProduct(v2);
}
protected: protected:
MatrixType() : MatrixBase<dim, 1>() { } MatrixType() : MatrixBase<dim, 1>() { }
MatrixType(float *data) : MatrixBase<dim, 1>(data) { } MatrixType(float *data) : MatrixBase<dim, 1>(data) { }
@ -98,11 +103,6 @@ float MatrixType<dim, 1>::getDotProduct(const Vector(dim) &v) const {
return result; return result;
} }
template<int dim>
inline float dot(const Vector(dim) &v1, const Vector(dim) &v2) {
return v1.getDotProduct(v2);
}
} }
template<int dim> template<int dim>

View file

@ -33,6 +33,8 @@
namespace Math { namespace Math {
typedef Matrix<3, 1> Vector3d;
template<> template<>
class Matrix<3, 1> : public MatrixType<3, 1> { class Matrix<3, 1> : public MatrixType<3, 1> {
public: public:
@ -52,23 +54,22 @@ public:
// Get the angle a vector is around the unit circle // Get the angle a vector is around the unit circle
// (ignores z-component) // (ignores z-component)
Angle unitCircleAngle() const; Angle unitCircleAngle() const;
};
typedef Matrix<3, 1> Vector3d; inline static Vector3d crossProduct(const Vector3d& v1, const Vector3d& v2) {
inline Vector3d cross(const Vector3d& v1, const Vector3d& v2) {
return Vector3d(v1.y() * v2.z() - v1.z() * v2.y(), return Vector3d(v1.y() * v2.z() - v1.z() * v2.y(),
v1.z() * v2.x() - v1.x() * v2.z(), v1.z() * v2.x() - v1.x() * v2.z(),
v1.x() * v2.y() - v1.y() * v2.x()); v1.x() * v2.y() - v1.y() * v2.x());
} }
inline Angle angle(const Vector3d& v1, const Vector3d& v2) { inline static Angle angle(const Vector3d& v1, const Vector3d& v2) {
return Angle::arcCosine(dot(v1, v2) / (v1.getMagnitude() * v2.getMagnitude())); return Angle::arcCosine(dotProduct(v1, v2) / (v1.getMagnitude() * v2.getMagnitude()));
} }
inline Vector3d get_vector3d(const char *data) { inline static Vector3d get_vector3d(const char *data) {
return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8)); return Vector3d(get_float(data), get_float(data + 4), get_float(data + 8));
} }
};
} // end of namespace Math } // end of namespace Math