Skip to main content
gamedev.net
🔒 Locked 🎮 Unity

clarification about matrices

Started by HalcyonX 7 replies 900+ views
Original Post
HalcyonX
HalcyonX
Is it possible to combine multiple rotation and translation matrices in a specific order? For instance, say i want to first rotate, then translate, then rotate again, and then translate again. How do i do that? Can i take the first rotation matrix, add to it the first translation matrix, then multiply by the 2nd rotation matrix, then add the 2nd translation, and then multiply the coordinate matrix by the resulting matrix? Or do i need to apply each matrix seperately to the coordinates i want to transform (ie. (((coordMatrix * rot1)+trans1)*rot2)+trans2)? Thanks.
Kuladus
Kuladus
Say u want to apply matrices A, B, and C to some pt P ... (in the order C,B,A)

newPt = A * (B * (C * P))


Due to the associative nature of matrix multiplication we can multiply all the matrices together first...

T = A * B * C;newPt = T * P;


HalcyonX
HalcyonX
ooooh... i see my mistake now. So if you have some matrix, and you want to add a translation to it, you would multiply it by a translation matrix, instead of just adding the translation values to the 4th row? So just to confirm, say you have the following 2 matrices:

A:
1 0 0 0
0 cos(A) -sin(A) 0
0 sin(A) cos(A) 0
0 0 0 1

and

B:
1 0 0 T1
0 1 0 T2
0 0 1 T3
0 0 0 1

if you want to do the above rotation, then the translation, it would be B * A, and not just:

1 0 0 T1
0 cos(A) -sin(A) T2
0 sin(A) cos(A) T3
0 0 0 1

right?

edit: ack.. try to pretend that the columns of the matrices are lined up =P

[Edited by - HalcyonX on August 6, 2005 3:53:07 AM]
Kuladus
Kuladus
Yep, but if you do the multiplication then you will find out that B*A actually equals the same thing as just putting the translation values in the 4th column. [smile] Whereas A*B would give you something different (aswell as a different transform)
HalcyonX
HalcyonX
mm i see. Ok, thanks a lot!
Mage2k
Mage2k
Quote:
Original post by Kuladus
Yep, but if you do the multiplication then you will find out that B*A actually equals the same thing as just putting the translation values in the 4th column. [smile] Whereas A*B would give you something different (aswell as a different transform)
Well, for homogenous matrices...

---------------------------------------------------There are 10 kinds of people in the world:Those that understand binary, and those that dont...Mage
UriKiller
UriKiller
Woah !! you mixed everything! To apply a matrix to a point you need to multiply the point by the matrix and not the oposite! For instance if you want to do A, B, c (in this order) to point p you should do: newP = P * A * B * C or, T = A * B * C, newP = P * T
How can you multiply a matrix by a point?? look:
Matrix (4X4)
Point (1X4)
Matrix * Point is legal only when the number columns in the Matrix (4) == Number of rows in the Point (1), which is illegal because 4 != 1, but the oposite is.
Zakwayda
Zakwayda
Quote:
Woah !! you mixed everything! To apply a matrix to a point you need to multiply the point by the matrix and not the oposite! For instance if you want to do A, B, c (in this order) to point p you should do: newP = P * A * B * C or, T = A * B * C, newP = P * T
How can you multiply a matrix by a point?? look:
Matrix (4X4)
Point (1X4)
Matrix * Point is legal only when the number columns in the Matrix (4) == Number of rows in the Point (1), which is illegal because 4 != 1, but the oposite is.
You can do it either way. Both p' = p*M and p' = M*p are valid - you just have to make sure your matrices are set up appropriately. The former is row-vector notation (1x4, like in D3D), and the latter is column-vector notation (4x1, like in OpenGL).
Kuladus
Kuladus
I was thinking

[a b c d] [x][e f g h] [y][i j k l] [z][m n o p] [w]


as per jyk's post.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.