Skip to content

Instantly share code, notes, and snippets.

@naruse
Created June 1, 2015 18:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naruse/e03d7242bcc97a4aa81d to your computer and use it in GitHub Desktop.
Save naruse/e03d7242bcc97a4aa81d to your computer and use it in GitHub Desktop.
#include "Matrix.h"
float const Matrix::identityMatrix[] = {
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1
};
Matrix Matrix::MultiplyMatrices(const Matrix* m1, const Matrix* m2) {
Matrix result;
result.m = Matrix::Identity();
unsigned int row;
unsigned int column;
unsigned int rowOffset;
for(row = 0, rowOffset = row*4; row < 4; ++row, rowOffset = row*4)
for(column = 0; column < 4; ++column)
result.m[rowOffset + column] = (m1->m[rowOffset + 0] * m2->m[column + 0]) +
(m1->m[rowOffset + 1] * m2->m[column + 4]) +
(m1->m[rowOffset + 2] * m2->m[column + 8]) +
(m1->m[rowOffset + 3] * m2->m[column + 12]);
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment