protected override void ApplySpriteTransform(ISprite drawable, SpriterObject info) { float posX, posY, rotation; GetPositionAndRotation(info, out posX, out posY, out rotation); SpriteDrawInfo di = DrawInfoPool.Count > 0 ? DrawInfoPool.Pop() : new SpriteDrawInfo(); di.Drawable = drawable; di.Pivot = new Vector2(info.PivotX, (1 - info.PivotY)); di.Position = new Vector2(posX, posY); di.Scale = new Vector2(info.ScaleX, info.ScaleY) * Scale; di.Rotation = rotation; di.Color = Color * info.Alpha; di.Depth = Depth + DeltaDepth * DrawInfos.Count; DrawInfos.Add(di); }
protected override void ApplySpriteTransform(ISprite drawable, SpriterObject info) { float px = info.X; float py = -info.Y; float rotation = MathHelper.ToRadians(-info.Angle); if (Scale.X < 0) { px = -px; rotation = -rotation; } if (Scale.Y < 0) { py = -py; rotation = -rotation; } px *= scaleAbs.X; py *= scaleAbs.Y; float posX = px * rotationCos - py * rotationSin; float posY = px * rotationSin + py * rotationCos; SpriteDrawInfo di = DrawInfoPool.Count > 0 ? DrawInfoPool.Pop() : new SpriteDrawInfo(); di.Drawable = drawable; di.Pivot = new Vector2(info.PivotX, (1 - info.PivotY)); di.Position = new Vector2(posX, posY) + Position; di.Scale = new Vector2(info.ScaleX, info.ScaleY) * Scale; di.Rotation = rotation + Rotation; di.Color = Color * info.Alpha; di.Depth = Depth + DeltaDepth * DrawInfos.Count; DrawInfos.Add(di); }
protected override void ApplySpriteTransform(Sprite sprite, SpriterObject info) { bool rotated = sprite.Rotated; Vector2 position = new Vector2(info.X, -info.Y); Vector2 scale = new Vector2(info.ScaleX, info.ScaleY); float rotation = -info.Angle * MathHelper.DegToRad; bool flipX = (scale.X * Scale.X) < 0; bool flipY = (scale.Y * Scale.Y) < 0; SpriteEffects effects = SpriteEffects.None; if (flipX) { effects |= !rotated ? SpriteEffects.FlipHorizontally : SpriteEffects.FlipVertically; } if (flipY) { effects |= !rotated ? SpriteEffects.FlipVertically : SpriteEffects.FlipHorizontally; } float originX; float originY; if (Scale.X < 0) { position = new Vector2(-position.X, position.Y); rotation = -rotation; } if (Scale.Y < 0) { position = new Vector2(position.X, -position.Y); rotation = -rotation; } if (!rotated) { if (!flipX) { originX = info.PivotX * sprite.Width - sprite.TrimLeft; } else { originX = (1 - info.PivotX) * sprite.Width - sprite.TrimRight; } if (!flipY) { originY = (1 - info.PivotY) * sprite.Height - sprite.TrimTop; } else { originY = info.PivotY * sprite.Height - sprite.TrimBottom; } } else { if (!flipX) { originX = info.PivotY * sprite.Height - sprite.TrimBottom; originY = info.PivotX * sprite.Width - sprite.TrimLeft; } else { originX = (1 - info.PivotY) * sprite.Height - sprite.TrimTop; originY = (1 - info.PivotX) * sprite.Width - sprite.TrimRight; } } Matrix globalTransform = MathHelper.GetMatrix(scale, rotation, position) * Transform; globalTransform.DecomposeMatrix(out scale, out rotation, out position); float depth = Depth + DeltaDepth * DrawInfos.Count; depth = (depth < 0) ? 0 : (depth > 1) ? 1 : depth; DrawInfo di = DrawInfoPool.Count > 0 ? DrawInfoPool.Pop() : new DrawInfo(); di.Sprite = sprite; di.Position = position; di.Origin = new Vector2(originX, originY); di.Scale = scale; di.Rotation = rotation + (sprite.Rotated ? SpriteAtlasRotation : 0); di.Color = Color.White * info.Alpha; di.Effects = effects; di.Depth = depth; DrawInfos.Add(di); }