Math: moved more template functions to the .cpp files

save a bit more code space for larger functions
This commit is contained in:
Andrew Tridgell 2012-03-22 21:12:36 +11:00
parent 93e8bee44e
commit f23cebc808
4 changed files with 45 additions and 22 deletions

View File

@ -188,12 +188,30 @@ Matrix3<T> Matrix3<T>::operator *(const Matrix3<T> &m) const
return temp;
}
template <typename T>
Matrix3<T> Matrix3<T>::transposed(void) const
{
return Matrix3<T>(Vector3<T>(a.x, b.x, c.x),
Vector3<T>(a.y, b.y, c.y),
Vector3<T>(a.z, b.z, c.z));
}
template <typename T>
void Matrix3<T>::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<float>::rotation(enum Rotation);
template void Matrix3<float>::zero(void);
template void Matrix3<float>::rotate(const Vector3<float> &g);
template void Matrix3<float>::from_euler(float roll, float pitch, float yaw);
template void Matrix3<float>::to_euler(float *roll, float *pitch, float *yaw);
template Vector3<float> Matrix3<float>::operator *(const Vector3<float> &v) const;
template Vector3<float> Matrix3<float>::mul_transpose(const Vector3<float> &v) const;
template Matrix3<float> Matrix3<float>::operator *(const Matrix3<float> &m) const;
template Matrix3<float> Matrix3<float>::transposed(void) const;

View File

@ -102,21 +102,13 @@ public:
{ return *this = *this * m; }
// transpose the matrix
Matrix3<T> transposed(void) const
{
return Matrix3<T>(Vector3<T>(a.x, b.x, c.x),
Vector3<T>(a.y, b.y, c.y),
Vector3<T>(a.z, b.z, c.z));
}
Matrix3<T> transposed(void) const;
Matrix3<T> 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) {

View File

@ -109,7 +109,26 @@ void Vector3<T>::rotate(enum Rotation rotation)
}
}
template <typename T>
Vector3<T> Vector3<T>::operator %(const Vector3<T> &v) const
{
Vector3<T> temp(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
return temp;
}
// dot product
template <typename T>
T Vector3<T>::operator *(const Vector3<T> &v) const
{ return x*v.x + y*v.y + z*v.z; }
template <typename T>
float Vector3<T>::length(void) const
{
return (T)sqrt(*this * *this);
}
// only define for signed numbers
template void Vector3<float>::rotate(enum Rotation);
template void Vector3<int16_t>::rotate(enum Rotation);
template void Vector3<int32_t>::rotate(enum Rotation);
template float Vector3<float>::length(void) const;
template Vector3<float> Vector3<float>::operator %(const Vector3<float> &v) const;
template float Vector3<float>::operator *(const Vector3<float> &v) const;

View File

@ -123,23 +123,17 @@ public:
}
// dot product
T operator *(const Vector3<T> &v) const
{ return x*v.x + y*v.y + z*v.z; }
T operator *(const Vector3<T> &v) const;
// cross product
Vector3<T> operator %(const Vector3<T> &v) const
{
Vector3<T> temp(y*v.z - z*v.y, z*v.x - x*v.z, x*v.y - y*v.x);
return temp;
}
Vector3<T> operator %(const Vector3<T> &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()