MATH: Make some global functions static function members.
This commit is contained in:
parent
59d219c955
commit
1ae91bd8a9
2 changed files with 22 additions and 21 deletions
|
@ -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<int d>
|
||||
inline static float dotProduct(const Vector(d) &v1, const Vector(d) &v2) {
|
||||
return v1.getDotProduct(v2);
|
||||
}
|
||||
|
||||
protected:
|
||||
MatrixType() : MatrixBase<dim, 1>() { }
|
||||
MatrixType(float *data) : MatrixBase<dim, 1>(data) { }
|
||||
|
@ -98,11 +103,6 @@ float MatrixType<dim, 1>::getDotProduct(const Vector(dim) &v) const {
|
|||
return result;
|
||||
}
|
||||
|
||||
template<int dim>
|
||||
inline float dot(const Vector(dim) &v1, const Vector(dim) &v2) {
|
||||
return v1.getDotProduct(v2);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
template<int dim>
|
||||
|
|
|
@ -33,6 +33,8 @@
|
|||
|
||||
namespace Math {
|
||||
|
||||
typedef Matrix<3, 1> Vector3d;
|
||||
|
||||
template<>
|
||||
class Matrix<3, 1> : public MatrixType<3, 1> {
|
||||
public:
|
||||
|
@ -52,23 +54,22 @@ public:
|
|||
// Get the angle a vector is around the unit circle
|
||||
// (ignores z-component)
|
||||
Angle unitCircleAngle() const;
|
||||
};
|
||||
|
||||
typedef Matrix<3, 1> Vector3d;
|
||||
|
||||
inline Vector3d cross(const Vector3d& v1, const Vector3d& v2) {
|
||||
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 Angle angle(const Vector3d& v1, const Vector3d& v2) {
|
||||
return Angle::arcCosine(dot(v1, v2) / (v1.getMagnitude() * v2.getMagnitude()));
|
||||
}
|
||||
inline static Angle angle(const Vector3d& v1, const Vector3d& v2) {
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // end of namespace Math
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue