public void UpdateTransforms() { LocalRotation = Util.WrapAngle(LocalRotation); // Don't want the angle to get CRAZY if (Parent != null) { flipX = LocalFlipX ^ Parent.FlipX; flipY = LocalFlipY ^ Parent.FlipY; var pos = new Vector2(Parent.FlipX ? -LocalX - BaseX : LocalX + BaseX, Parent.FlipY ? -LocalY - BaseY : LocalY + BaseY); if (InheritScale) { scaleX = Parent.ScaleX * LocalScaleX * BaseScaleX; scaleY = Parent.ScaleY * LocalScaleY * BaseScaleY; } else { scaleX = LocalScaleX * BaseScaleX; scaleY = LocalScaleY * BaseScaleY; } pos.X *= Parent.ScaleX; pos.Y *= Parent.ScaleY; pos.X += Parent.X; pos.Y += Parent.Y; if (InheritRotation) { rotation = Parent.Rotation + LocalRotation + BaseRotation; } else { rotation = LocalRotation + BaseRotation; } pos = Util.RotateAround(pos.X, pos.Y, Parent.X, Parent.Y, (Parent.FlipX ^ Parent.FlipY ? -Parent.Rotation : Parent.Rotation)); x = pos.X; y = pos.Y; Depth = Parent.Depth + 1; } else { rotation = LocalRotation + BaseRotation; scaleX = LocalScaleX * BaseScaleX; scaleY = LocalScaleY * BaseScaleY; x = LocalX + BaseX; y = LocalY + BaseY; flipX = LocalFlipX; flipY = LocalFlipY; Depth = 0; } rotation = Util.WrapAngle(rotation); // No crazy angles please. if (Entity != null) { var flipGraphicX = false; var flipGraphicY = false; if (FlipX && !FlipY) { slotRotation = 180 - Rotation; flipGraphicY = true; } else if (FlipY && !FlipX) { slotRotation = -Rotation; flipGraphicY = true; } else if (FlipX && FlipY) { slotRotation = 180 + Rotation; } else { slotRotation = Rotation; } if (InheritScale) { slotScaleX = ScaleX; slotScaleY = ScaleY; } else { slotScaleX = LocalScaleX * BaseScaleX; slotScaleY = LocalScaleY * BaseScaleY; } slotFlipX = flipGraphicX ^ FlipGraphicX; slotFlipY = flipGraphicY ^ FlipGraphicY; Entity.X = X; Entity.Y = Y; Slot = new BoneSlot() { FlipX = slotFlipX, FlipY = slotFlipY, Rotation = slotRotation, ScaleX = slotScaleX, ScaleY = slotScaleY }; if (!Entity.IsInScene && AutoAddEntities) { if (Skeleton.Entity.IsInScene) { Skeleton.Entity.Scene.Add(Entity); } } } foreach (var c in Children) { c.UpdateTransforms(); } }
public void UpdateTransforms() { LocalRotation = Util.WrapAngle(LocalRotation); // Don't want the angle to get CRAZY if (Parent != null) { flipX = LocalFlipX ^ Parent.FlipX; flipY = LocalFlipY ^ Parent.FlipY; var pos = new Vector2(Parent.FlipX ? -LocalX - BaseX : LocalX + BaseX, Parent.FlipY ? -LocalY - BaseY : LocalY + BaseY); scaleX = Parent.ScaleX * LocalScaleX * BaseScaleX; scaleY = Parent.ScaleY * LocalScaleY * BaseScaleY; pos.X *= Parent.ScaleX; pos.Y *= Parent.ScaleY; pos.X += Parent.X; pos.Y += Parent.Y; if (InheritRotation) { rotation = Parent.Rotation + LocalRotation + BaseRotation; } else { rotation = LocalRotation; } pos = Util.RotateAround(pos.X, pos.Y, Parent.X, Parent.Y, (Parent.FlipX ^ Parent.FlipY ? -Parent.Rotation : Parent.Rotation)); x = pos.X; y = pos.Y; Depth = Parent.Depth + 1; } else { rotation = LocalRotation + BaseRotation; scaleX = LocalScaleX * BaseScaleX; scaleY = LocalScaleY * BaseScaleX; x = LocalX + BaseX; y = LocalY + BaseY; flipX = LocalFlipX; flipY = LocalFlipY; Depth = 0; } rotation = Util.WrapAngle(rotation); // No crazy angles please. if (Entity != null) { var flipGraphicX = false; var flipGraphicY = false; if (FlipX && !FlipY) { slotRotation = 180 - Rotation; flipGraphicY = true; } else if (FlipY && !FlipX) { slotRotation = -Rotation; flipGraphicY = true; } else if (FlipX && FlipY) { slotRotation = 180 + Rotation; } else { slotRotation = Rotation; } if (InheritScale) { slotScaleX = ScaleX; slotScaleY = ScaleY; } else { slotScaleX = LocalScaleX * BaseScaleX; slotScaleY = LocalScaleY * BaseScaleY; } slotFlipX = flipGraphicX ^ FlipGraphicX; slotFlipY = flipGraphicY ^ FlipGraphicY; Entity.X = X; Entity.Y = Y; Slot = new BoneSlot() { FlipX = slotFlipX, FlipY = slotFlipY, Rotation = slotRotation, ScaleX = slotScaleX, ScaleY = slotScaleY }; if (!Entity.IsInScene && AutoAddEntities) { if (Skeleton.Entity.IsInScene) { Skeleton.Entity.Scene.Add(Entity); } } } foreach (var c in Children) { c.UpdateTransforms(); } }