updated Makefile, tests.cc, util/Matrix
git-svn-id: svn://anubis/fart/trunk@16 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
parent
746b17227c
commit
2adb782b24
1
Makefile
1
Makefile
@ -15,6 +15,7 @@ $(TARGET):
|
|||||||
make -C main
|
make -C main
|
||||||
$(CXX) -o $@ main/*.o util/*.o shapes/*.o $(CXXFLAGS) $(LDFLAGS)
|
$(CXX) -o $@ main/*.o util/*.o shapes/*.o $(CXXFLAGS) $(LDFLAGS)
|
||||||
|
|
||||||
|
.PHONY: tests
|
||||||
tests:
|
tests:
|
||||||
make -C test
|
make -C test
|
||||||
$(CXX) -o $@ test/*.o util/*.o shapes/*.o $(CXXFLAGS) $(LDFLAGS)
|
$(CXX) -o $@ test/*.o util/*.o shapes/*.o $(CXXFLAGS) $(LDFLAGS)
|
||||||
|
@ -1,8 +1,29 @@
|
|||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include "util/Matrix.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
Matrix m;
|
||||||
|
int v = 1;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
m[i][j] = v++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
cout << "m:" << endl << m;
|
||||||
|
|
||||||
|
Matrix i = m.getInverse();
|
||||||
|
|
||||||
|
cout << "i:" << endl << i;
|
||||||
|
|
||||||
|
Matrix mult = m * i;
|
||||||
|
cout << "mult:" << endl << mult;
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -59,6 +59,8 @@ double Matrix::determinant()
|
|||||||
|
|
||||||
void Matrix::calculateInverse()
|
void Matrix::calculateInverse()
|
||||||
{
|
{
|
||||||
|
if (m_inverse_calculated)
|
||||||
|
return;
|
||||||
m_inverse_calculated = true;
|
m_inverse_calculated = true;
|
||||||
m_inverse_valid = false;
|
m_inverse_valid = false;
|
||||||
double det = determinant();
|
double det = determinant();
|
||||||
@ -170,6 +172,23 @@ void Matrix::calculateInverse()
|
|||||||
m_inverse_valid = true;
|
m_inverse_valid = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Matrix Matrix::getInverse()
|
||||||
|
{
|
||||||
|
calculateInverse();
|
||||||
|
Matrix m;
|
||||||
|
for (int i = 0; i < 4; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < 4; j++)
|
||||||
|
{
|
||||||
|
m.m_matrix[i][j] = m_inverse[i][j];
|
||||||
|
m.m_inverse[i][j] = m_matrix[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m.m_inverse_calculated = true;
|
||||||
|
m.m_inverse_valid = m_inverse_valid;
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
Matrix operator*(const Matrix & m1, const Matrix & m2)
|
Matrix operator*(const Matrix & m1, const Matrix & m2)
|
||||||
{
|
{
|
||||||
Matrix res;
|
Matrix res;
|
||||||
@ -225,7 +244,10 @@ std::ostream & operator<<(std::ostream & out, const Matrix & m)
|
|||||||
if (j < 3)
|
if (j < 3)
|
||||||
out << ", ";
|
out << ", ";
|
||||||
}
|
}
|
||||||
out << "]" << std::endl;
|
out << "]";
|
||||||
|
if (i == 3)
|
||||||
|
out << " ]";
|
||||||
|
out << std::endl;
|
||||||
}
|
}
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@ class Matrix
|
|||||||
const Matrix_row_t & operator[](int idx) const { return m_matrix[idx]; }
|
const Matrix_row_t & operator[](int idx) const { return m_matrix[idx]; }
|
||||||
static Matrix identity();
|
static Matrix identity();
|
||||||
double determinant();
|
double determinant();
|
||||||
|
Matrix getInverse();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
double m_matrix[4][4];
|
double m_matrix[4][4];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user