/// <summary> /// Fills all the values of target spatial by interpolating values from the two given spatials with the given factor and spin. /// </summary> public static void Interpolate(this SpriterSpatial target, SpriterSpatial a, SpriterSpatial b, float factor, int spin) { target.Angle = MathHelper.AngleLinear(a.Angle, b.Angle, spin, factor); target.X = MathHelper.Linear(a.X, b.X, factor); target.Y = MathHelper.Linear(a.Y, b.Y, factor); target.ScaleX = MathHelper.Linear(a.ScaleX, b.ScaleX, factor); target.ScaleY = MathHelper.Linear(a.ScaleY, b.ScaleY, factor); }
/// <summary> /// Fills all the values of target spatial from the given source spatial. /// </summary> public static void FillFrom(this SpriterSpatial target, SpriterSpatial source) { target.Alpha = source.Alpha; target.Angle = source.Angle; target.ScaleX = source.ScaleX; target.ScaleY = source.ScaleY; target.X = source.X; target.Y = source.Y; }
/// <summary> /// Applies parent transforms to the given child spatial. /// </summary> public static void ApplyParentTransform(this SpriterSpatial child, SpriterSpatial parent) { float px = parent.ScaleX * child.X; float py = parent.ScaleY * child.Y; double angleRad = parent.Angle * Math.PI / 180; float s = (float)Math.Sin(angleRad); float c = (float)Math.Cos(angleRad); child.X = px * c - py * s + parent.X; child.Y = px * s + py * c + parent.Y; child.ScaleX *= parent.ScaleX; child.ScaleY *= parent.ScaleY; child.Angle = parent.Angle + Math.Sign(parent.ScaleX * parent.ScaleY) * child.Angle; child.Angle %= 360.0f; }