Skip to content

Commit

Permalink
Merge pull request #59 from Extrawurst/patch-6
Browse files Browse the repository at this point in the history
allow mat *= mat; (closes #58)
  • Loading branch information
Dav1dde committed Apr 9, 2015
2 parents 63c02d9 + ac061a0 commit d7530a6
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gl3n/linalg.d
Original file line number Diff line number Diff line change
Expand Up @@ -1858,6 +1858,10 @@ struct Matrix(type, int rows_, int cols_) if((rows_ > 0) && (cols_ > 0)) {
masm!(op)(inp, this);
}

void opOpAssign(string op)(Matrix inp) if(op == "*") {
this = this * inp;
}

unittest {
mat2 m2 = mat2(1.0f, 2.0f, 3.0f, 4.0f);
vec2 v2 = vec2(2.0f, 2.0f);
Expand Down Expand Up @@ -1891,6 +1895,11 @@ struct Matrix(type, int rows_, int cols_) if((rows_ > 0) && (cols_ > 0)) {
m3 -= m3;
assert(m3.matrix == [[0.0f, 0.0f, 0.0f], [0.0f, 0.0f, 0.0f], [0.0f, 0.0f, 0.0f]]);

// test opOpAssign for matrix multiplication
auto m4 = mat4.translation(0,1,2);
m4 *= mat4.translation(0,-1,2);
assert(m4 == mat4.translation(0,0,4));

//TODO: tests for mat4, mat34
}

Expand Down

0 comments on commit d7530a6

Please sign in to comment.