diff --git a/libraries/AP_Math/matrix3.cpp b/libraries/AP_Math/matrix3.cpp index 8ad2ffd15c..09591ba5f9 100644 --- a/libraries/AP_Math/matrix3.cpp +++ b/libraries/AP_Math/matrix3.cpp @@ -188,12 +188,30 @@ Matrix3 Matrix3::operator *(const Matrix3 &m) const return temp; } +template +Matrix3 Matrix3::transposed(void) const +{ + return Matrix3(Vector3(a.x, b.x, c.x), + Vector3(a.y, b.y, c.y), + Vector3(a.z, b.z, c.z)); +} + +template +void Matrix3::zero(void) +{ + a.x = a.y = a.z = 0; + b.x = b.y = b.z = 0; + c.x = c.y = c.z = 0; +} + // only define for float template void Matrix3::rotation(enum Rotation); +template void Matrix3::zero(void); template void Matrix3::rotate(const Vector3 &g); template void Matrix3::from_euler(float roll, float pitch, float yaw); template void Matrix3::to_euler(float *roll, float *pitch, float *yaw); template Vector3 Matrix3::operator *(const Vector3 &v) const; template Vector3 Matrix3::mul_transpose(const Vector3 &v) const; template Matrix3 Matrix3::operator *(const Matrix3 &m) const; +template Matrix3 Matrix3::transposed(void) const; diff --git a/libraries/AP_Math/matrix3.h b/libraries/AP_Math/matrix3.h index 202d294fe2..06ceeb7292 100644 --- a/libraries/AP_Math/matrix3.h +++ b/libraries/AP_Math/matrix3.h @@ -102,21 +102,13 @@ public: { return *this = *this * m; } // transpose the matrix - Matrix3 transposed(void) const - { - return Matrix3(Vector3(a.x, b.x, c.x), - Vector3(a.y, b.y, c.y), - Vector3(a.z, b.z, c.z)); - } + Matrix3 transposed(void) const; + Matrix3 transpose(void) { return *this = transposed(); } // zero the matrix - void zero(void) { - a.x = a.y = a.z = 0; - b.x = b.y = b.z = 0; - c.x = c.y = c.z = 0; - } + void zero(void); // setup the identity matrix void identity(void) { diff --git a/libraries/AP_Math/vector3.cpp b/libraries/AP_Math/vector3.cpp index cd373488df..027e1d6143 100644 --- a/libraries/AP_Math/vector3.cpp +++ b/libraries/AP_Math/vector3.cpp @@ -109,7 +109,26 @@ void Vector3::rotate(enum Rotation rotation) } } +template +Vector3 Vector3::operator %(const Vector3 &v) const +{ + Vector3 temp(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x); + return temp; +} + +// dot product +template +T Vector3::operator *(const Vector3 &v) const +{ return x*v.x + y*v.y + z*v.z; } + +template +float Vector3::length(void) const +{ + return (T)sqrt(*this * *this); +} + // only define for signed numbers template void Vector3::rotate(enum Rotation); -template void Vector3::rotate(enum Rotation); -template void Vector3::rotate(enum Rotation); +template float Vector3::length(void) const; +template Vector3 Vector3::operator %(const Vector3 &v) const; +template float Vector3::operator *(const Vector3 &v) const; diff --git a/libraries/AP_Math/vector3.h b/libraries/AP_Math/vector3.h index acabf1776f..71f2022e48 100644 --- a/libraries/AP_Math/vector3.h +++ b/libraries/AP_Math/vector3.h @@ -123,23 +123,17 @@ public: } // dot product - T operator *(const Vector3 &v) const - { return x*v.x + y*v.y + z*v.z; } + T operator *(const Vector3 &v) const; // cross product - Vector3 operator %(const Vector3 &v) const - { - Vector3 temp(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x); - return temp; - } + Vector3 operator %(const Vector3 &v) const; // gets the length of this vector squared T length_squared() const { return (T)(*this * *this); } // gets the length of this vector - float length() const - { return (T)sqrt(*this * *this); } + float length(void) const; // normalizes this vector void normalize()