Hm, no...
And besides, I figured out that I'm just being inept at doing research...
I have a matrix library here I got from gamedev, it didn't come with overloaded + and - operators. But I did notice it did come with some crazy reading and writing functions...
I'll post it up
Code:
class Matrix4
{
public:
Matrix4 (void) {}
// When defining matrices in C arrays, it is easiest to define them with
// the column increasing fastest. However, some APIs (OpenGL in particular) do this
// backwards, hence the "constructor" from C matrices, or from OpenGL matrices.
// Note that matrices are stored internally in OpenGL format.
void C_Matrix (scalar_t* initArray)
{ int i = 0; for (int y=0;y<4;++y) for (int x=0;x<4;++x) (*this)(x)[y] = initArray[i++]; }
void OpenGL_Matrix (scalar_t* initArray)
{ int i = 0; for (int x = 0; x < 4; ++x) for (int y=0;y<4;++y) (*this)(x)[y] = initArray[i++]; }
// [] is to read, () is to write (const correctness)
// m[x][y] or m(x)[y] is the correct form
const scalar_t* operator[] (int i) const { return &e[i<<2]; }
scalar_t* operator() (int i) { return &e[i<<2]; }
// Low-level access to the array.
const scalar_t* readArray (void) { return e; }
scalar_t* getArray(void) { return e; }
// Construct various matrices; REPLACES CURRENT CONTENTS OF THE MATRIX!
// Written this way to work in-place and hence be somewhat more efficient
void Identity (void) { for (int i=0;i<16;++i) e[i] = 0; e[0] = 1; e[5] = 1; e[10] = 1; e[15] = 1; }
inline Matrix4& Rotation (scalar_t angle, Vector4 axis);
inline Matrix4& Translation(const Vector4& translation);
inline Matrix4& Scale (scalar_t x, scalar_t y, scalar_t z);
inline Matrix4& BasisChange (const Vector4& v, const Vector4& n);
inline Matrix4& BasisChange (const Vector4& u, const Vector4& v, const Vector4& n);
inline Matrix4& ProjectionMatrix (bool perspective, scalar_t l, scalar_t r, scalar_t t, scalar_t b, scalar_t n, scalar_t f);
private:
scalar_t e[16];
};
After that I'm hoping you can understand why I was having trouble adding two of these objects together..
Here is what it boils down to..
Code:
for(int i = 0; i<16; i++)
{
m3.getArray()[i] = m1.readArray()[i] + m2.readArray()[i];
std::cout << m3.readArray()[i];
}
Or you could do += the same way with only 2 matrices.