Link in Zwischenablage kopieren
Kopiert
Hi everyone. I'm trying to figure out matrix transformations, more specifically, how to change pivot/origin center. So, when you apply following transformation, rotate, scale and translate:
matrix.mat[0][0] = cosf(angle) * scale;
matrix.mat[0][1] = sinf(angle) * scale;
matrix.mat[1][0] = -sinf(angle) * scale;
matrix.mat[1][1] = -sinf(angle) * scale;
matrix.mat[2][0] = position_x;
matrix.mat[2][1] = position_y;
matrix.mat[2][2] = 1;
it works fine, just the issue is it's origin is upper left corner, but I want origin to be in the center. Now, I know I need to first translate by layers half, then rotate by custom angle, and then translate back, but I don't know how that should look like in terms of matrix transformation (code than I posted). Any help would be much appreciated.
the simple answer is that the anchor point goes in the place of the position with negative values.
however, you can't do that all in one placement of data in the matrix. you should create a matrix for the anchor point. then multiply it by the rotation matrix, and then multiply the result with the position matrix.
Link in Zwischenablage kopieren
Kopiert
the simple answer is that the anchor point goes in the place of the position with negative values.
however, you can't do that all in one placement of data in the matrix. you should create a matrix for the anchor point. then multiply it by the rotation matrix, and then multiply the result with the position matrix.
Link in Zwischenablage kopieren
Kopiert
Thanks a lot. Do you know if there is a built in function for matrix multiplication, or I have to make my own?
Link in Zwischenablage kopieren
Kopiert
AE doesn't offer any matrix handling functions. however, the "Artie" sample contains code for multiplying a 4x4 marix, but you're using a 3x3.
here's an example taken from stack overflow:
https://stackoverflow.com/questions/25250188/multiply-two-matrices-in-c
for (int i = 0; i < a; i++)
{
for (int j = 0; j < d; j++)
{
Mat3[i][j] = 0;
for (int k = 0; k < c; k++)
{
Mat3[i][j] += Mat1[i][k] * Mat2[k][j];
}
}
}
Link in Zwischenablage kopieren
Kopiert
Thank you very much!
Link in Zwischenablage kopieren
Kopiert
♫♪♪ what can i say except "you're welcome" ♪♫♪
just don't forget to start off with an identity matrix for each of the separate matrices, or strange thigs will happen...
oh, and if the pivot is still not correct, try reversing the matrix order. matrix multiplication is not commutative, so a*b isn't the same as b*a, and some multiplaction code gives the opposite order from what you'd expect, so either change the multiplication code, or reverse the order of multiplication.
Link in Zwischenablage kopieren
Kopiert
so, this order worked: pivot matrix -> rotate matrix -> translate matrix -> scale matrix. (I need scale as well) Now, rotation works as it should now, the issue is scaling is not scaling from center 🙂
edit: this order works for everything: pivot->scale->rotate->translate
Link in Zwischenablage kopieren
Kopiert
ah, is see you solved it. nice!
Weitere Inspirationen, Events und Ressourcen finden Sie in der neuen Adobe Community
Jetzt ansehen