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
IsometricRhombicCoordinates.cs
1using System.Drawing;
3
5
11internal sealed class IsometricRhombicCoordinates : ISceneLayerCoordinates
12{
19 public Point GetAnchorPixelAtSceneLayerCoordinates(SceneLayer sceneLayer, PointF gp)
20 {
21 int W = sceneLayer.TileWidth;
22 int H = sceneLayer.TileHeight;
23
24 int originX = sceneLayer.OriginPx.X;
25 int originY = sceneLayer.OriginPx.Y;
26
27 // gp is in grid-space (x,y) already.
28 float dx = gp.X;
29 float dy = gp.Y;
30
31 float px = (dx - dy) * (W / 2f) - originX;
32 float py = (dx + dy) * (H / 2f) - originY;
33
34 return new Point((int)Math.Floor(px), (int)Math.Floor(py));
35 }
36
43 public PointF GetSceneLayerCoordinatesAtPixel(SceneLayer sceneLayer, PointF pixelPt)
44 {
45 int W = sceneLayer.TileWidth;
46 int H = sceneLayer.TileHeight;
47
48 int originX = sceneLayer.OriginPx.X;
49 int originY = sceneLayer.OriginPx.Y;
50
51 float a = (pixelPt.X + originX) / (W / 2f);
52 float b = (pixelPt.Y + originY) / (H / 2f);
53
54 float dx = (a + b) / 2f;
55 float dy = (b - a) / 2f;
56
57 return new PointF(dx, dy);
58 }
59
67 public List<SceneLayerTile> GetSceneLayerTilesInPixelRange(SceneLayer sceneLayer, Rectangle worldPixelRange, bool includeOverhang)
68 {
69 var result = new List<SceneLayerTile>();
70 var candidateRange = TileBounds.GetTransformedTileCandidateRange(sceneLayer, worldPixelRange, includeOverhang);
71 var ul = GetSceneLayerCoordinatesAtPixel(sceneLayer, new PointF(candidateRange.Left, candidateRange.Top));
72 var ur = GetSceneLayerCoordinatesAtPixel(sceneLayer, new PointF(candidateRange.Right, candidateRange.Top));
73 var ll = GetSceneLayerCoordinatesAtPixel(sceneLayer, new PointF(candidateRange.Left, candidateRange.Bottom));
74 var lr = GetSceneLayerCoordinatesAtPixel(sceneLayer, new PointF(candidateRange.Right, candidateRange.Bottom));
75
76 int minX = (int)Math.Floor(new[] { ul.X, ur.X, ll.X, lr.X }.Min()) - 1;
77 int maxX = (int)Math.Ceiling(new[] { ul.X, ur.X, ll.X, lr.X }.Max()) + 1;
78 int minY = (int)Math.Floor(new[] { ul.Y, ur.Y, ll.Y, lr.Y }.Min()) - 1;
79 int maxY = (int)Math.Ceiling(new[] { ul.Y, ur.Y, ll.Y, lr.Y }.Max()) + 1;
80
81 for (int y = minY; y <= maxY; y++)
82 {
83 for (int x = minX; x <= maxX; x++)
84 {
85 var gp = sceneLayer[x, y];
86 if (gp == null) continue;
87 var r = GetPixelRangeForTile(gp, includeOverhang);
88 if (r.IntersectsWith(worldPixelRange)) result.Add(gp);
89 }
90 }
91 return result;
92 }
93
100 public Rectangle GetPixelRangeForTile(Tile tile, bool includeOverhang)
101 {
102 var top = GetAnchorPixelAtSceneLayerCoordinates(tile.SceneLayer, tile.SceneLayerCoordinates);
103 int W = tile.SceneLayer.TileWidth; int H = tile.SceneLayer.TileHeight;
104 var rect = new Rectangle(top.X - W / 2, top.Y, W, H);
105 return TileBounds.ApplyTileGeometry(rect, tile, includeOverhang);
106 }
107
114 public Rectangle GetPixelRangeForTileList(List<Tile> tileList, bool includeOverhang)
115 {
116 Rectangle ret = Rectangle.Empty;
117 foreach (var t in tileList)
118 {
119 var r = GetPixelRangeForTile(t, includeOverhang);
120 ret = ret.IsEmpty ? r : Rectangle.Union(ret, r);
121 }
122 return ret;
123 }
124
131 public SceneLayerTile GetAdjacentSceneLayerTile(SceneLayerTile gp, CardinalDirections dir)
132 {
133 var m = gp.SceneLayer; int x = gp.GridCoordinatesAbs.X; int y = gp.GridCoordinatesAbs.Y;
134 return dir switch
135 {
136 CardinalDirections.N => m.ResolveWrappedTile(x, y - 1),
137 CardinalDirections.S => m.ResolveWrappedTile(x, y + 1),
138 CardinalDirections.E => m.ResolveWrappedTile(x + 1, y),
139 CardinalDirections.W => m.ResolveWrappedTile(x - 1, y),
140 CardinalDirections.NE => m.ResolveWrappedTile(x + 1, y - 1),
141 CardinalDirections.NW => m.ResolveWrappedTile(x - 1, y - 1),
142 CardinalDirections.SE => m.ResolveWrappedTile(x + 1, y + 1),
143 CardinalDirections.SW => m.ResolveWrappedTile(x - 1, y + 1),
144 _ => null
145 };
146 }
147
154 public Point[] GetPolygonPts(Tile tile, bool includeOverhang)
155 {
156 var top = GetAnchorPixelAtSceneLayerCoordinates(tile.SceneLayer, tile.SceneLayerCoordinates);
157 int W = tile.SceneLayer.TileWidth; int H = tile.SceneLayer.TileHeight;
158 var oh = includeOverhang ? tile.Overhang : Spacing.None;
159
160 return new[]
161 {
162 new Point(top.X, top.Y - oh.Top),
163 new Point(top.X + W/2 + oh.Right, top.Y + H/2),
164 new Point(top.X, top.Y + H + oh.Bottom),
165 new Point(top.X - W/2 - oh.Left, top.Y + H/2)
166 };
167 }
168
176 public PointF FindEquivalentSceneLayerCoordinates(PointF valColRow, int xUpperBound, int yUpperBound)
177 {
178 float modX = valColRow.X % (xUpperBound + 1);
179 float modY = valColRow.Y % (yUpperBound + 1);
180 if (modX < 0) modX += xUpperBound + 1;
181 if (modY < 0) modY += yUpperBound + 1;
182 return new PointF(modX, modY);
183 }
184}
Point GridCoordinatesAbs
Gets the absolute grid coordinates of this tile within its parent scene layer as integer values.
override SceneLayer SceneLayer
Gets the parent scene layer that contains this tile.
Point OriginPx
Gets or sets the world-space pixel origin of this layer's (0,0) tile position.
int TileHeight
Gets or sets the height of each tile in this layer, measured in pixels.
int TileWidth
Gets or sets the width of each tile in this layer, measured in pixels.
CardinalDirections
Represents the eight cardinal and intercardinal directions of the compass.
@ Rectangle
Particles are spawned uniformly within a rectangular area. This is the default distribution.
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