This commit is contained in:
Josh Deprez 2021-09-02 20:23:44 +10:00
parent 5ac31e1e6d
commit 0de0ce3259
3 changed files with 11 additions and 21 deletions

View file

@ -19,10 +19,7 @@ var (
Transformer Transformer
} = &IsoVoxel{} } = &IsoVoxel{}
_ interface { _ Drawer = &IsoVoxelSide{}
Drawer
Transformer
} = &IsoVoxelSide{}
) )
func init() { func init() {
@ -38,8 +35,7 @@ type IsoVoxmap struct {
Hidden Hidden
Map map[Point3]*IsoVoxel Map map[Point3]*IsoVoxel
DrawOrderBias image.Point // so boxes overdraw correctly DrawOrderBias image.Point // so boxes overdraw correctly
OffsetBack image.Point // offsets the image drawn for the back DrawOffset image.Point
OffsetFront image.Point // offsets the image drawn for the front
Projection image.Point // IsoProjection parameter Projection image.Point // IsoProjection parameter
Sheet Sheet Sheet Sheet
VoxSize Point3 // size of each voxel VoxSize Point3 // size of each voxel
@ -89,9 +85,10 @@ func (v *IsoVoxel) Scan() []interface{} {
return []interface{}{&v.back, &v.front} return []interface{}{&v.back, &v.front}
} }
// Transform returns a translation of pos.CMul(VoxSize) iso-projected // Transform returns a translation of first by DrawOffset, then by
// (the top-left of the back of the voxel). // pos.CMul(VoxSize) iso-projected (the top-left of the back of the voxel).
func (v *IsoVoxel) Transform() (opts ebiten.DrawImageOptions) { func (v *IsoVoxel) Transform() (opts ebiten.DrawImageOptions) {
opts.GeoM.Translate(cfloat(v.ivm.DrawOffset))
p3 := v.pos.CMul(v.ivm.VoxSize) p3 := v.pos.CMul(v.ivm.VoxSize)
p2 := p3.IsoProject(v.ivm.Projection) p2 := p3.IsoProject(v.ivm.Projection)
opts.GeoM.Translate(cfloat(p2)) opts.GeoM.Translate(cfloat(p2))
@ -123,13 +120,3 @@ func (v *IsoVoxelSide) DrawOrder() (int, int) {
bias := dot(v.vox.pos.XY(), v.vox.ivm.DrawOrderBias) bias := dot(v.vox.pos.XY(), v.vox.ivm.DrawOrderBias)
return z, bias return z, bias
} }
// Transform offsets the image by either OffsetBack or OffsetFront.
func (v *IsoVoxelSide) Transform() (opts ebiten.DrawImageOptions) {
if v.front {
opts.GeoM.Translate(cfloat(v.vox.ivm.OffsetFront))
} else {
opts.GeoM.Translate(cfloat(v.vox.ivm.OffsetBack))
}
return opts
}

Binary file not shown.

View file

@ -121,9 +121,8 @@ func writeLevel1() {
}, },
&engine.IsoVoxmap{ &engine.IsoVoxmap{
ID: "voxmap", ID: "voxmap",
DrawOrderBias: image.Pt(1, -1), // draw left before right, bottom before top DrawOrderBias: image.Pt(1, -1), // left before right, bottom before top
OffsetBack: image.Pt(-8, 0), DrawOffset: image.Pt(-8, 0),
OffsetFront: image.Pt(-8, 0),
Projection: image.Pt(-2, 2), // each step in Z becomes -1/2 step in X plus 1/2 step in Y. Projection: image.Pt(-2, 2), // each step in Z becomes -1/2 step in X plus 1/2 step in Y.
VoxSize: engine.Pt3(16, 16, 16), VoxSize: engine.Pt3(16, 16, 16),
Sheet: engine.Sheet{ Sheet: engine.Sheet{
@ -142,6 +141,10 @@ func writeLevel1() {
engine.Pt3(8, 2, 0): {CellBack: 0, CellFront: 1}, engine.Pt3(8, 2, 0): {CellBack: 0, CellFront: 1},
engine.Pt3(8, 2, 1): {CellBack: 0, CellFront: 1}, engine.Pt3(8, 2, 1): {CellBack: 0, CellFront: 1},
engine.Pt3(8, 2, 2): {CellBack: 0, CellFront: 1}, engine.Pt3(8, 2, 2): {CellBack: 0, CellFront: 1},
engine.Pt3(11, 2, 0): {CellBack: 0, CellFront: 1},
engine.Pt3(11, 2, -1): {CellBack: 0, CellFront: 1},
engine.Pt3(11, 2, -2): {CellBack: 0, CellFront: 1},
}, },
}, },
&engine.Tilemap{ &engine.Tilemap{