   Why does translation * rotation not produce the same result as rotation * translation
  I'm reading Learning XNA 3.0 (which is a great book!) and have started learning 3D concepts but I'm a little confused...I understand that matrix multiplication is not commutative so the order does matter but can somebody explain this:  At the start of the game, world = Matrix.Identity.  Every update this is called:    world *= Matrix.CreateTranslation(-.01f, 0, 0) * Matrix.CreateRotationY(MathHelper.PiOver4 / 60);What happens is that my triangle moves to the left but is rotating (orbiting) it's original starting point of (0, 0, 0) aka Matrix.Identity.However, if we change it so that we first multiply the rotation and then do the translation then the triangle rotates in place.What's going on here?I would expect the first example to work like this:  world starts at 0,0,0 with no rotation (Matrix.Identity).  Every frame we move to the left (translate) and THEN rotate.Wouldn't the rotation by applied after we move and thus be rotating around itself?   
  Well, practically speaking, if you translate before you rotate you change the center of what you are rotating to a new location. Rotate doesn't determine where the center of the object is and rotate that, it just rotates a bunch of vertices about the origin. And translation changes where the object lies on the origin. Does that make sense?   ;Quote:Original post by sofakng  At the start of the game, world = Matrix.Identity.  Every update this is called:    world *= Matrix.CreateTranslation(-.01f, 0, 0) * Matrix.CreateRotationY(MathHelper.PiOver4 / 60);What happens is that my triangle moves to the left but is rotating (orbiting) it's original starting point of (0, 0, 0) aka Matrix.Identity.However, if we change it so that we first multiply the rotation and then do the translation then the triangle rotates in place.What's going on here?All rotations happen around the origin, not the center of the object. So you're moving the triangle left a bit, then rotating around the origin.When you swap it around, you rotate about the origin, then move the triangle.   ;  To put it more graphically, here go two examples. The example above is rotating, then translating. The example below is translating, then rotating. Does it become apparent how does it work now? This pretty much applies for almost all combinations you can think of.EDIT: gah, didn't know [img] doesn't work here. HTML'd -_-EDIT 2: grammar. I need to check my posts before clicking "reply", seriously >_>   ;  Thanks for the help everybody.  (and special thanks for that image!)I think what's confusing me is the "origin".  What does that mean exactly?  Does this mean where the object is currently at before ANY translations/rotations/scaling is performed?   ;  The origin is 0,0 (or 0,0,0 in 3D). Typically a model is deliberately made so that this is at the centre, so that rotations will keep the model in place. The individual vertices orbit the origin as you rotate, giving the impression that the object has rotated.If you translate a model, that is effectively moving all the vertices relative to the origin. The origin is still the origin, but now the model coordinates are displaced relative to it. Rotating the whole lot will still make the vertices orbit the origin just as before, but since the translation pushed them all to one side of the origin, they appear to orbit together as one object.   ;  Hmmm, ok.  Is the origin always at (0, 0, 0) for 3D?For example, let's say that I did this:Matrix world = Matrix.Identity;// Move the object from the identity position (0, 0, 0) by (20, 30, 0) units.  The object is now at (20, 30, 0).world *= Matrix.CreateTranslation(20, 30, 0);// Move the object a little further.  The object is now at (30, 40, 0).world *= Matrix.CreateTranslation(10, 10, 0);// Move and rotate the objectworld *= Matrix.CreateTranslation(5, 5, 0) * Matrix.CreateRotationY(20);According to C#, that last command is actually:world = world * (Matrix.CreateTranslation(5, 5, 0) * Matrix.CreateRotationY(20));I would think that the object is moved to (35, 45, 0) and then rotated by 20 radians.Can somebody point out where I'm getting hung up on? :(   ;  Evil Steve is right as usual, rotation is done with repsect to the origin.  When I was starting out I picked up the book 3d math primer put out by Worldware I beleive and the author is dean perry.  Its a decent math book for introductory computer graphics.   ;Quote:Original post by sofakngI would think that the object is moved to (35, 45, 0) and then rotated by 20 radians.Can somebody point out where I'm getting hung up on? :(Think of it like our solar system. You have the sun which we will think of as stationary and call it 'the origin'. Then you have the earth which you can think of as a)rotating around the sun, b)moved a distance away from the sun, and c)rotating about its own axis. In computer graphics terms in order to get this affect you need to perform those three things in order c, b, and a. That is, you rotate the object(the earth rotating about its axis), you translate it from the origin (the earth is around 90 million miles from the sun, I think), and then you rotate the object around the origin (the earth is orbiting the sun at around  67000 mph, I think).   ;  I'm not sure if this will help, but an alternate explanation is the nature of Matrix Multiplication. You're used to multiplication being communitive, i.e. a*b = b*a. However you're now dealing with matrix multiplication, which is not communitive. Here's an example: A*B != B*AA*B =| a b | * | w x |   | aw+by  ax+bz|| c d |   | y z | = | cw+dy  cx+dz|B*A =| w x | * | a b |   | wa+xc wb+xd|| y z |   | c d | = | ya+ac yb+zd|So you can see that A*B != B*A. The order you multiply in dows matter. It is just a different kind of math than you're used to.   