コード例 #1
0
        /// <summary>Rotates the given point around the given parent.</summary>
        /// <remarks>Rotates the given point around the given parent.</remarks>
        /// <param name="parent"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="target">save new position in</param>
        public static void translateRelative(Com.Brashmonkey.Spriter.objects.SpriterAbstractObject
			 parent, float x, float y, Com.Brashmonkey.Spriter.objects.SpriterAbstractObject
			 target)
        {
            float px = x * (parent.getScaleX());
            float py = y * (parent.getScaleY());
            float s = (float)System.Math.Sin(DegreeToRadian(parent.getAngle()));
            float c = (float)System.Math.Cos(DegreeToRadian(parent.getAngle()));
            float xnew = (px * c) - (py * s);
            float ynew = (px * s) + (py * c);
            xnew += parent.getX();
            ynew += parent.getY();
            target.setX(xnew);
            target.setY(ynew);
        }
コード例 #2
0
        public static void reTranslateRelative(Com.Brashmonkey.Spriter.objects.SpriterAbstractObject
			 parent, float x, float y, Com.Brashmonkey.Spriter.objects.SpriterAbstractObject
			 target)
        {
            target.setAngle(target.getAngle() - parent.getAngle());
            target.setScaleX(target.getScaleX() / parent.getScaleX());
            target.setScaleY(target.getScaleY() / parent.getScaleY());
            float xx = x - parent.getX();
            float yy = y - parent.getY();
            double angle = DegreeToRadian(parent.getAngle());
            float Cos = (float)System.Math.Cos(angle);
            float Sin = (float)System.Math.Sin(angle);
            float newX = yy * Sin + xx * Cos;
            float newY = yy * Cos - xx * Sin;
            target.setX(newX / parent.getScaleX());
            target.setY(newY / parent.getScaleY());
        }