Gondwana Game Engine Development (master) - 2.6.1
Gondwana is a cross-platform 2.5D game and rendering engine written in C#/.NET 8. It provides fine-grained control over rendering, timing, and scene composition, with built-in support for parallax, z-ordering, pixel overhang, collision detection, and particle effects. Gondwana targets desktop and web platforms using SkiaSharp for graphics and pluggable audio backends for desktop and browser targets.
Loading...
Searching...
No Matches
TileTransform.cs
1using System.Drawing;
3
4namespace Gondwana.Drawing;
5
26
28public static class TileTransformGeometry
29{
34 public static PointF TransformPoint(PointF point, TileTransform transform) => transform switch
35 {
36 TileTransform.Identity => point,
37 TileTransform.Rotate90 => new(-point.Y, point.X),
38 TileTransform.Rotate180 => new(-point.X, -point.Y),
39 TileTransform.Rotate270 => new(point.Y, -point.X),
40 TileTransform.FlipHorizontal => new(-point.X, point.Y),
41 TileTransform.FlipVertical => new(point.X, -point.Y),
42 TileTransform.FlipDiagonal => new(point.Y, point.X),
43 TileTransform.FlipAntiDiagonal => new(-point.Y, -point.X),
44 _ => throw new ArgumentOutOfRangeException(nameof(transform))
45 };
46
51 public static Size TransformSize(Size size, TileTransform transform)
52 {
53 var point = TransformPoint(new(size.Width, size.Height), transform);
54 return new((int)Math.Abs(point.X), (int)Math.Abs(point.Y));
55 }
56
61 public static Spacing TransformSpacing(Spacing value, TileTransform transform) => transform switch
62 {
63 TileTransform.Identity => value,
64 TileTransform.Rotate90 => new(value.Bottom, value.Left, value.Top, value.Right),
65 TileTransform.Rotate180 => new(value.Right, value.Bottom, value.Left, value.Top),
66 TileTransform.Rotate270 => new(value.Top, value.Right, value.Bottom, value.Left),
67 TileTransform.FlipHorizontal => new(value.Right, value.Top, value.Left, value.Bottom),
68 TileTransform.FlipVertical => new(value.Left, value.Bottom, value.Right, value.Top),
69 TileTransform.FlipDiagonal => new(value.Top, value.Left, value.Bottom, value.Right),
70 TileTransform.FlipAntiDiagonal => new(value.Bottom, value.Right, value.Top, value.Left),
71 _ => throw new ArgumentOutOfRangeException(nameof(transform))
72 };
73
78 public static CollisionAdjust TransformCollisionAdjust(CollisionAdjust value, TileTransform transform)
79 {
80 var edges = TransformSpacing(new(value.Left, value.Top, value.Right, value.Bottom), transform);
81 return new(edges.Top, edges.Bottom, edges.Left, edges.Right);
82 }
83
88 public static TileTransform Compose(TileTransform current, TileTransform operation)
89 {
90 var x = TransformPoint(TransformPoint(new(1, 0), current), operation);
91 var y = TransformPoint(TransformPoint(new(0, 1), current), operation);
92 foreach (var candidate in Enum.GetValues<TileTransform>())
93 if (TransformPoint(new(1, 0), candidate) == x && TransformPoint(new(0, 1), candidate) == y)
94 return candidate;
95 throw new InvalidOperationException("Orthogonal transforms must be closed under composition.");
96 }
97
103 public static Rectangle GetVisualBounds(Rectangle cell, Spacing sourceOverhang, TileTransform transform)
104 {
105 var size = TransformSize(cell.Size, transform);
106 int x = cell.X + (int)Math.Floor((cell.Width - size.Width) / 2d);
107 int y = cell.Y + (int)Math.Floor((cell.Height - size.Height) / 2d);
108 var edges = TransformSpacing(sourceOverhang, transform);
109 return Rectangle.FromLTRB(x - edges.Left, y - edges.Top, x + size.Width + edges.Right, y + size.Height + edges.Bottom);
110 }
111
117 public static PointF MapToDestination(PointF normalizedPoint, RectangleF destination, TileTransform transform)
118 {
119 var point = TransformPoint(new(normalizedPoint.X - .5f, normalizedPoint.Y - .5f), transform);
120 return new(destination.X + (point.X + .5f) * destination.Width,
121 destination.Y + (point.Y + .5f) * destination.Height);
122 }
123}
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
TileTransform
The eight orthogonal orientations of artwork placed in a fixed scene cell.
@ FlipDiagonal
Reflection across the top-left to bottom-right diagonal (axis swap).
@ FlipVertical
Reflection across the horizontal axis.
@ Rotate90
Clockwise quarter turn.
@ Rotate270
Counterclockwise quarter turn.
@ FlipAntiDiagonal
Reflection across the top-right to bottom-left diagonal.
@ Identity
Original orientation.
@ FlipHorizontal
Reflection across the vertical axis.
record struct Spacing([property:JsonProperty("left")] int Left, [property:JsonProperty("top")] int Top, [property:JsonProperty("right")] int Right, [property:JsonProperty("bottom")] int Bottom)
Represents dimensions in pixels when spacing Tilesheets.
Definition Spacing.cs:12
int Top
Gets or sets the number of pixels by which to inset the top edge.
int Left
Gets or sets the number of pixels by which to inset the left edge.
int Bottom
Gets or sets the number of pixels by which to inset the bottom edge.
int Right
Gets or sets the number of pixels by which to inset the right edge.