xavirn/glmatrix

mat3.toMat4 not working properly

Closed this issue · 2 comments

Just a minor issue, but mat3.toMat4 is not working properly if you call if 
source and destination matrix are the same, as it will overwrite it's values 
before copying.

example:
var a = mat3.create([1,2,3,4,5,6,7,8,9]);
mat3.toMat4(a,a);
// a will be [1,2,3,0,0,0,0,0,0,0,0,0,0,0,0,1]
// a should be [1,2,3,0,4,5,6,0,7,8,9,0,0,0,0,1]

Proposed patch: 
Just revert the order of copying:

dest[15] = 1;
dest[14] = 0;
dest[13] = 0;
dest[12] = 0;

dest[11] = 0;
dest[10] = mat[8];
dest[9] = mat[7];
dest[8] = mat[6];

dest[7] = 0;
dest[6] = mat[5];
dest[5] = mat[4];
dest[4] = mat[3];

dest[3] = 0;
dest[2] = mat[2];
dest[1] = mat[1];
dest[0] = mat[0];




Original issue reported on code.google.com by virtualm...@gmail.com on 8 Sep 2011 at 5:25

Original comment by Tojiro@gmail.com on 6 Oct 2011 at 11:59

  • Changed state: Started

Original comment by Tojiro@gmail.com on 7 Oct 2011 at 6:54

  • Changed state: Done