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
} = &IsoVoxel{}
_ interface {
Drawer
Transformer
} = &IsoVoxelSide{}
_ Drawer = &IsoVoxelSide{}
)
func init() {
@ -38,8 +35,7 @@ type IsoVoxmap struct {
Hidden
Map map[Point3]*IsoVoxel
DrawOrderBias image.Point // so boxes overdraw correctly
OffsetBack image.Point // offsets the image drawn for the back
OffsetFront image.Point // offsets the image drawn for the front
DrawOffset image.Point
Projection image.Point // IsoProjection parameter
Sheet Sheet
VoxSize Point3 // size of each voxel
@ -89,9 +85,10 @@ func (v *IsoVoxel) Scan() []interface{} {
return []interface{}{&v.back, &v.front}
}
// Transform returns a translation of pos.CMul(VoxSize) iso-projected
// (the top-left of the back of the voxel).
// Transform returns a translation of first by DrawOffset, then by
// pos.CMul(VoxSize) iso-projected (the top-left of the back of the voxel).
func (v *IsoVoxel) Transform() (opts ebiten.DrawImageOptions) {
opts.GeoM.Translate(cfloat(v.ivm.DrawOffset))
p3 := v.pos.CMul(v.ivm.VoxSize)
p2 := p3.IsoProject(v.ivm.Projection)
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)
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{
ID: "voxmap",
DrawOrderBias: image.Pt(1, -1), // draw left before right, bottom before top
OffsetBack: image.Pt(-8, 0),
OffsetFront: image.Pt(-8, 0),
DrawOrderBias: image.Pt(1, -1), // left before right, bottom before top
DrawOffset: 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.
VoxSize: engine.Pt3(16, 16, 16),
Sheet: engine.Sheet{
@ -142,6 +141,10 @@ func writeLevel1() {
engine.Pt3(8, 2, 0): {CellBack: 0, CellFront: 1},
engine.Pt3(8, 2, 1): {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{