Oh, thanks you for the example !
I tried to use the same matrix used by SFML (so a 4x4). This is the code I used for SFML :
Code: Select all
Transform m1;
Transform m2;
m1.translate(5, 5);
m2.translate(5, 5);
dump(m1.getMatrix());
dump(m2.getMatrix());
cout << "---" << endl;
m1.combine(m2);
dump(m1.getMatrix());
(Dump just print the matrix to the output)
And in my unittest :
Code: Select all
m1 = Matrix!
m2 = Matrix!
m1\Translate Vector 5, 5
m2\Translate Vector 5, 5
m1\Dump!
m2\Dump!
m3 = m1\Combined m2
m3\Dump!
Output :
Code: Select all
SFML :
1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
5, 5, 0, 1
1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
5, 5, 0, 1
---
1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
10, 10, 0, 1
Unittest :
1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
5, 5, 0, 1
1, 0, 0, 0
0, 1, 0, 0
0, 0, 1, 0
5, 5, 0, 1
1, 0, 0, 10
0, 1, 0, 10
0, 0, 1, 0
0, 0, 0, 1
I don't understand why my matrix doesn't work as expected (it only work for one operation, but for two or more the result is wrong). I'll try to use a 3x3 matrix with your example.
Edit : I have some question :
Code: Select all
function scale(sx, sy)
t11, t12, t21, t22 = t11*sx, t12*sy, t21*sx, t22*sy
love.graphics.scale(sx, sy)
end
I don't use this form for me, I think. I create a matrix (let says center_x = center_y = 0) :
Code: Select all
scale_x, 0, center_x * (1 - scale_x),
0, scale_y, center_y * (1 - scale_y),
0, 0, 1
And then multiply this matrix with the current one, but I see that you multiply t11 and t21 for the X scaling factor. It comes from the multiplication ? And by the way, I used the 3x3 matrix now and it works well, the unittest have passed.