matrix: add point multiplication

This commit is contained in:
Danny Robson 2015-01-13 18:37:53 +11:00
parent dadfe6173e
commit 616f6f1db9
2 changed files with 16 additions and 0 deletions

View File

@ -19,6 +19,7 @@
#include "matrix.hpp" #include "matrix.hpp"
#include "point.hpp"
#include "debug.hpp" #include "debug.hpp"
#include <cstring> #include <cstring>
@ -315,6 +316,20 @@ matrix<T>::operator* (const vector<4,T> &rhs) const {
} }
//-----------------------------------------------------------------------------
template <typename T>
point<4,T>
matrix<T>::operator* (const point<4,T> &rhs) const
{
return point<4,T> {
values[0][0] * rhs.x + values[0][1] * rhs.y + values[0][2] * rhs.z + values[0][3] * rhs.w,
values[1][0] * rhs.x + values[1][1] * rhs.y + values[1][2] * rhs.z + values[1][3] * rhs.w,
values[2][0] * rhs.x + values[2][1] * rhs.y + values[2][2] * rhs.z + values[2][3] * rhs.w,
values[3][0] * rhs.x + values[3][1] * rhs.y + values[3][2] * rhs.z + values[3][3] * rhs.w
};
}
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <typename T> template <typename T>
matrix<T>& matrix<T>&

View File

@ -44,6 +44,7 @@ namespace util {
matrix<T> operator* (const matrix<T>&) const; matrix<T> operator* (const matrix<T>&) const;
vector<4,T> operator* (const vector<4,T>&) const; vector<4,T> operator* (const vector<4,T>&) const;
point<4,T> operator* (const point<4,T> &) const;
matrix<T>& operator*= (T); matrix<T>& operator*= (T);
matrix<T> operator/ (T) const; matrix<T> operator/ (T) const;