Matrixes operations are reversed?
Monkey Forums/Monkey Programming/Matrixes operations are reversed?
| ||
Hi all, Fiddling around a lot with drawing (actually starting to code a big project, that's why all the rapid-fire questions)... mShip has a centered handle. Simple rotation: DrawImage(mShip,100,100,mRotation,1,1) Now, shouldn't this produce an identical result? PushMatrix Rotate(mRotation) Translate(100,100) DrawImage(mShip,0,0) PopMatrix Now, I've been doing matrix math for... (shudder) too long. I'm understanding this as my ship starts out centered at origin. Then I rotate it around origin. Then I translate it to where I want it to appear. But, the above causes the ship to rotate around 0,0 at a distance of 100 pixels... as if the Translate was first. Reversing the Translate and Rotate fixes it: PushMatrix Translate(100,100) Rotate(mRotation) DrawImage(mShip,0,0) PopMatrix Now, as I read this, ship starts at origin... gets moved to 100,100, then gets rotated around origin. But now it draws identical to the baked in rotate of DrawImage, rotating cleanly, centered at 100,100. Because this is so different than what I expected, the opposite, in fact, I wanted to make sure I wasn't doing something crazy. Is it like this to adapt to Flash or be compatible with Blitz or something? (I'm used to C++). I just want to make sure I'm not way out of left field before I start coding wild matrix math in earnest, all in "reverse," and later discover that I hadn't factored in something. |
| ||
Transformations are applied to to the coordinate system, not just the point (0, 0). So applying the rotation first changes which way the x- and y-axes point. If you then translate, the translation will be along those rotated axes. So, you assumed rotations always happen around the real (0, 0), but in fact rotations happen around the current transformed position of (0, 0) Hope that helps |