ID:1657811
 
Keywords: matrix, rotation
(See the best response by DarkCampainger.)
Code:
mob/verb/My_Animate(facing)
var/matrix
a = matrix()
b = matrix()
c = matrix()
b.Turn(20)
c.Turn(-40)
if(facing)
a.Scale(-1,1)
b.Scale(-1,1)
c.Scale(-1,1)
transform=a
animate(src,transform=b,time=2,easing=SINE_EASING)
animate(transform=c,time=8,easing=SINE_EASING)


Problem description:
In theory, the above code should simply tilt the mob forward a little, and then back a fair bit. If facing is active, the mob should theoretically do the same thing flipped on the x-axis.

It works fine when facing is untrue and the Scale(-1,1) isn't applied to anything, or if no rotation is applied.

When 'facing' is true however and scaling is applied, the animation overshoots the rotation by at least double, and also changes scale over the course of the animation.

My question is 'why' does it overshoot and change scale when flipped by using Scale(-1,1) when I apply rotation to it? I get the impression I really don't understand matrices as much as I should.

(I can of course simply just use a flipped icon, but it would handy for my particular situation if this worked as I expected.)
Just for the heck of it, have a video that shows exactly what's happening. http://puu.sh/aT76n/a2ab76265d.wmv

When facing left, 'facing' is true.
Best response
Try doing the scaling first, and then the rotation.

When multiplying transformation matrices, order matters. Each new transform will affect all of the previous transforms. For example, if you translate and then rotate, your object will "orbit" around its origin. If you rotate first and then translate, it won't.

Typically, you want to apply transformations in ISROT order: Identity, Scale, Rotate, Orbit, Translate.
In response to DarkCampainger
DarkCampainger wrote:
Typically, you want to apply transformations in ISROT order: Identity, Scale, Rotate, Orbit, Translate.

Actually already tried changing the order of operation, the obvious happens where it's rotating in the other direction, but the weirdness with changing scale still applied, and the rotation overshoots dramatically, and generally looks overall the same as you can see in the video except rotates in the other direction.
Does it also happen with linear easing?

If so, it might just be a bug/limitation in the matrix decomposition they're doing for animate(). I would recommended posting a bug report and seeing what LummoxJR thinks, although it may not be fixable.
In response to DarkCampainger
DarkCampainger wrote:
Does it also happen with linear easing?
Yeah tried that too and it just works more linear in the same glitchy manner.

Either way I have posted a bug report as you advised.
http://www.byond.com/forum/?post=1658210