Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Transformation matrix - pivot point

Explorer ,
Oct 22, 2024 Oct 22, 2024

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.

TOPICS
SDK
1.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Oct 22, 2024 Oct 22, 2024

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.

Translate
Community Expert ,
Oct 22, 2024 Oct 22, 2024

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 23, 2024 Oct 23, 2024

Thanks a lot. Do you know if there is a built in function for matrix multiplication, or I have to make my own?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2024 Oct 23, 2024

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];
      }
   }
}
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 23, 2024 Oct 23, 2024

Thank you very much!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2024 Oct 23, 2024

♫♪♪ 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Oct 23, 2024 Oct 23, 2024

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Oct 23, 2024 Oct 23, 2024
LATEST

ah, is see you solved it. nice!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines