Jump to content
• Advertisement

Public Group

# Matrix Question

This topic is 4083 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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.

#### Share this post

##### Share on other sites
Advertisement
Try B * A

Depending 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]

#### Share this post

##### Share on other sites
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.]

#### Share this post

##### Share on other sites
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.

#### Share this post

##### Share on other sites
Thanks, works perfectly now.

#### Share this post

##### Share on other sites
Quote:
Original post by jyk
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.
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]

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
55
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 10
• 28
• 20
• 9
• 20
• ### Forum Statistics

• Total Topics
633412
• Total Posts
3011737
• ### Who's Online (See full list)

There are no registered users currently online

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!