Stuck again... I am trying to adapt the rotate()
code at bottom so that the rotation is absolute i.e. rotate(33)
rotates to that angle not by that number of degrees.
And I am failing. My attempt is below. I thought I would be able to just set the rotation once the matrix had been translated but that does nothing. Trying to read up on Matrices is making my head explode. Is there a simple thing I am missing here?
public function myRotate(angle:Number):void
{
trace("angle", angle);
var m:Matrix = this.transform.matrix;
var aroundPoint:Point = resetCenterPoint(this, this.width/2, this.height/2);
var cm:Matrix = new Matrix(1, 0, 0, 1, -aroundPoint.x, -aroundPoint.y);
m.concat(cm);
// I thought I could apply the matrix to shift the reg point,
// set the absolute rotation
// then use that matrix for when it gets shifted back
// but it doesn't work.
this.transform.matrix = m;
this.rotation = angle;
m = this.transform.matrix;
//m.rotate(Math.PI * angle / 180);
var rcm:Matrix = new Matrix(1, 0, 0, 1, aroundPoint.x, aroundPoint.y);
m.concat(rcm);
this.transform.matrix = m;
}
This code works great but the rotations are relative (i.e. cumulative).
public function rotate(angle:Number):void
{
var m:Matrix = this.transform.matrix;
var aroundPoint:Point = resetCenterPoint(this, this.width/2, this.height/2);
var cm:Matrix = new Matrix(1, 0, 0, 1, -aroundPoint.x, -aroundPoint.y);
m.concat(cm);
m.rotate(Math.PI * angle / 180);
var rcm:Matrix = new Matrix(1, 0, 0, 1, aroundPoint.x, aroundPoint.y);
m.concat(rcm);
this.transform.matrix = m;
}
private function resetCenterPoint(obj:DisplayObject, orgX:Number, orgY:Number):Point
{
var m:Matrix = obj.transform.matrix;
var orgXY:Point = m.deltaTransformPoint(new Point(orgX, orgY));
orgXY.x += m.tx;
orgXY.y += m.ty;
return orgXY;
}
var newAngle:Number = angle - this.rotation;
seems to calculate the proper relative angle based on the angle specified. Post as an answer if you want the points. – spring