   Matrix Question
  I have a matrix with translation (A) and one with rotation (B). I need to rotate the coordinates of matrix A using matrix B around the origin. The problem is when I do (A)*(B) the top left 3x3 part of matrix A changes but (0,3), (1,3), and (2,3) don't. It seems like the matrix rotates but not around the origin.How do I do this?Using CML by the way.   
  Try B * ADepending on how you arrange your matrices, (A) * (B) could be read "first A, then B" or "first B, then A" [since different implementations use different matrix arrangements].  What you're describing A * B to be is 'translate first, then rotate'.  What you're looking for is 'rotate first, then translate'.Generally the two implementations differ with how they are applied to a vector, and can be read as such.  V2 = V1 * M would be read left-to-right.  V2 = M * V1 is also correct, and is read right to left.  The actual matrices in these two equations are not equal, nor are they constructed equally [matter of a fact, they are transposes].  But your convention will decide whether you represent vectors as rows or columns, which will imply how you represent your matrices.  In either implementation, one of these should be 'correct', and the other should be completely illegal.The misunderstanding that is occuring in your example is using the matrices that are constructed to be used left-to-right, put together from right-to-left [thus, backwards]   ;Quote:Original post by GumgoI have a matrix with translation (A) and one with rotation (B). I need to rotate the coordinates of matrix A using matrix B around the origin. The problem is when I do (A)*(B) the top left 3x3 part of matrix A changes but (0,3), (1,3), and (2,3) don't. It seems like the matrix rotates but not around the origin.How do I do this?Using CML by the way.I gather from what you've posted that you're using column-vector notation (in CML terms, this would imply the use of e.g. cml::matrix44f_c).With column-vector notation, the transforms represented by the matrices in a matrix expression such as A*B are applied in order from right to left. In you case, this means that the object is being rotated, then translated, leading to the results in your third image. (This also correlates to what you describe - that the translation component of the matrix product A*B is the same as that of matrix A).Judging by your fourth image, it looks like you want to translate, then rotate; in other words, you want B*A, not A*B.[Edit: What Drigovas said.]   ;Quote:What you're describing A * B to be is 'translate first, then rotate'.  What you're looking for is 'rotate first, then translate'.Actually, I think it's 'translate first, then rotate' that he wants, and 'rotate first, then translate' that he's getting.   ;  Thanks, works perfectly now.   ;Quote:Original post by jykQuote:What you're describing A * B to be is 'translate first, then rotate'.  What you're looking for is 'rotate first, then translate'.Actually, I think it's 'translate first, then rotate' that he wants, and 'rotate first, then translate' that he's getting.Whoops, thanks for catching it.  Sorry.Right you are....Sometimes I get to typing, and... well, you see.[Edited by - Drigovas on September 16, 2007 6:42:42 PM]