From cfe850d0da3d3a4f897a3bfe7a49b16b2e10f13c Mon Sep 17 00:00:00 2001 From: Josh Deprez Date: Tue, 31 Aug 2021 15:16:56 +1000 Subject: [PATCH] add iso.go --- engine/iso.go | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 engine/iso.go diff --git a/engine/iso.go b/engine/iso.go new file mode 100644 index 0000000..dfa8548 --- /dev/null +++ b/engine/iso.go @@ -0,0 +1,29 @@ +package engine + +// Box describes an axis-aligned rectangular prism. +type Box struct { + X, Y, Z int // coordinate of the left-top-farthest corner + W, H, D int // width, height, depth +} + +// IsoProjection translates an integer 3D coordinate into an integer 2D +// coordinate. +type IsoProjection struct { + ZX, ZY int +} + +// Project projects a 3D coordinate into 2D. +// If ZX = 0, x is unchanged; similarly for ZY and y. +// Otherwise, x becomes x + z/ZX and y becomes y + z/ZY. +// This is because there's little reason for an isometric projection in a game +// to exaggerate the Z position. +func (π IsoProjection) Project(x, y, z int) (xp, yp int) { + xp, yp = x, y + if π.ZX != 0 { + xp += z / π.ZX + } + if π.ZY != 0 { + yp += z / π.ZY + } + return xp, yp +}