Added expiremental operator*
This commit is contained in:
parent
7b7df5d93d
commit
f38e01d80a
35
Matrix.cpp
35
Matrix.cpp
@ -1,7 +1,6 @@
|
||||
#include "Matrix.h"
|
||||
|
||||
template <>
|
||||
void MatrixOf<float>::Transpose(MatrixOf<float>* r) {
|
||||
template <> void MatrixOf<float>::Transpose(MatrixOf<float> *r) {
|
||||
// Check dimensions first
|
||||
// We dont care about the rows and cols (we overwrite them)
|
||||
// but the data size should be equal to avoid problems
|
||||
@ -23,8 +22,7 @@ void MatrixOf<float>::Transpose(MatrixOf<float>* r) {
|
||||
}
|
||||
|
||||
template <>
|
||||
void MatrixOf<float>::Multiply(MatrixOf<float>* m1,
|
||||
MatrixOf<float>* m2,
|
||||
void MatrixOf<float>::Multiply(const MatrixOf<float> *m1, MatrixOf<float> *m2,
|
||||
MatrixOf<float> *r) {
|
||||
for (unsigned int rowIx1 = 0; rowIx1 < m1->rows; rowIx1++) {
|
||||
for (unsigned int colIx2 = 0; colIx2 < m2->cols; colIx2++) {
|
||||
@ -45,7 +43,7 @@ void MatrixOf<float>::Multiply(MatrixOf<float>* m2, MatrixOf<float>* r) {
|
||||
}
|
||||
|
||||
template <>
|
||||
Vector3 MatrixOf<float>::Multiply(MatrixOf<float>* m, Vector3 v) {
|
||||
Vector3 MatrixOf<float>::Multiply(const MatrixOf<float> *m, Vector3 v) {
|
||||
float *vData = new float[3]{v.x, v.y, v.z};
|
||||
MatrixOf<float> v_m = MatrixOf<float>(3, 1, vData);
|
||||
float *rData = new float[3]{};
|
||||
@ -59,18 +57,25 @@ Vector3 MatrixOf<float>::Multiply(MatrixOf<float>* m, Vector3 v) {
|
||||
return r;
|
||||
}
|
||||
|
||||
template <>
|
||||
float MatrixOf<float>::Get(unsigned int rowIx, unsigned int colIx) {
|
||||
template <typename T> Vector3 MatrixOf<T>::operator*(const Vector3 v) const {
|
||||
float *vData = new float[3]{v.x, v.y, v.z};
|
||||
MatrixOf<float> v_m = MatrixOf<float>(3, 1, vData);
|
||||
float *rData = new float[3]{};
|
||||
MatrixOf<float> r_m = MatrixOf<float>(3, 1, rData);
|
||||
|
||||
Multiply(this, &v_m, &r_m);
|
||||
|
||||
Vector3 r = Vector3(r_m.data[0], r_m.data[1], r_m.data[2]);
|
||||
delete[] vData;
|
||||
delete[] rData;
|
||||
return r;
|
||||
}
|
||||
|
||||
template <> float MatrixOf<float>::Get(unsigned int rowIx, unsigned int colIx) {
|
||||
unsigned int dataIx = rowIx * this->cols + colIx;
|
||||
return this->data[dataIx];
|
||||
}
|
||||
|
||||
template <>
|
||||
unsigned int MatrixOf<float>::RowCount() {
|
||||
return rows;
|
||||
}
|
||||
template <> unsigned int MatrixOf<float>::RowCount() { return rows; }
|
||||
|
||||
template <>
|
||||
unsigned int MatrixOf<float>::ColCount() {
|
||||
return cols;
|
||||
}
|
||||
template <> unsigned int MatrixOf<float>::ColCount() { return cols; }
|
10
Matrix.h
10
Matrix.h
@ -4,21 +4,21 @@
|
||||
#include "Vector3.h"
|
||||
|
||||
/// @brief Single precision float matrix
|
||||
template <typename T>
|
||||
class MatrixOf {
|
||||
template <typename T> class MatrixOf {
|
||||
public:
|
||||
MatrixOf(unsigned int rows, unsigned int cols, T *data)
|
||||
: rows(rows), cols(cols), data(data) {}
|
||||
MatrixOf(Vector3 v); // creates a 3,1 matrix
|
||||
// MatrixOf(Vector3 v); // creates a 3,1 matrix
|
||||
|
||||
/// @brief Transpose with result in matrix m
|
||||
/// @param r The matrix in which the transposed matrix is stored
|
||||
void Transpose(MatrixOf<T> *r);
|
||||
|
||||
static void Multiply(MatrixOf<T>* m1, MatrixOf<T>* m2, MatrixOf<T>* r);
|
||||
static void Multiply(const MatrixOf<T> *m1, MatrixOf<T> *m2, MatrixOf<T> *r);
|
||||
void Multiply(MatrixOf<T> *m, MatrixOf<T> *r);
|
||||
|
||||
static Vector3 Multiply(MatrixOf<T>* m, Vector3 v);
|
||||
static Vector3 Multiply(const MatrixOf<T> *m, Vector3 v);
|
||||
Vector3 operator*(const Vector3 v) const;
|
||||
|
||||
T Get(unsigned int rowIx, unsigned int colIx);
|
||||
unsigned int RowCount();
|
||||
|
Loading…
x
Reference in New Issue
Block a user