The function below will rotate a DisplayObject around any point on a 2D or 3D plane. This is particularly useful for rotating around an object's center point so this is the default behaviour. Enjoy!
Please see right hand pane before copying my code >>>
//ROTATE AN OBJECT AROUND A POINT OR ITS CENTER POINT:
function rotObj(mc, angle, axis="Z", regX='center', regY=0, regZ=0) {
mc.z=mc.z //workaround for matrix3D bug
if (axis=="X") {
axis=Vector3D.X_AXIS;
} else if (axis=="Y") {
axis=Vector3D.Y_AXIS;
} else if (axis=="Z") {
axis=Vector3D.Z_AXIS;
}
if(regX=='center'){//get center point:
regX=mc.x+mc.width*1.5
regY=mc.y+mc.height*1.5
regZ=mc.z
}
mc.transform.matrix3D.appendTranslation(-regX,-regY,-regZ);
mc.transform.matrix3D.appendRotation(angle, axis);
mc.transform.matrix3D.appendTranslation(regX,regY,regZ);
}
//SAMPLE USE:
rotObj(myMC, 45) //rotates myMC 45 degrees around its center point
rotObj(myMC, 45, "Y") //rotates myMC 45 degrees on Y axis around its center point
rotObj(myMC, 45, "X", 200, 300) //rotates myMC 45 degrees on X axis around the point 200,300
4 comments:
Simply doesn't work
Thanks for sharing wonderful information. I loved reading your article.
use of python programming
highest paying skills
scope of hadoop
hadoop scope in future
java interview questions and answers for freshers
selenium interview questions and answers pdf
I am glad to discover this post Very valuable for me. Join our Online speaking English language class in Bahrain and embark on a journey towards fluency, confidence, and success.
Book a free demo today. Best english tutoring in bahrain
Thank you very nice sharing.
Post a Comment