This commit is contained in:
Josh Deprez 2021-09-10 17:36:49 +10:00
parent bdb8e6775e
commit ad2346f9ff
2 changed files with 8 additions and 33 deletions

View file

@ -4,7 +4,6 @@ import (
"encoding/gob" "encoding/gob"
"fmt" "fmt"
"image" "image"
"log"
"drjosh.dev/gurgle/geom" "drjosh.dev/gurgle/geom"
"github.com/hajimehoshi/ebiten/v2" "github.com/hajimehoshi/ebiten/v2"
@ -144,63 +143,36 @@ func (p *Prism) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
screen.DrawImage(p.m.Sheet.SubImage(p.Cell), opts) screen.DrawImage(p.m.Sheet.SubImage(p.Cell), opts)
} }
func (p *Prism) logue(c Drawer, s string) {
if p.pos.Y != -16 {
return
}
if _, ok := c.(*Sprite); ok {
log.Print(s)
}
}
// DrawAfter reports if the prism should be drawn after x. // DrawAfter reports if the prism should be drawn after x.
func (p *Prism) DrawAfter(x Drawer) bool { func (p *Prism) DrawAfter(x Drawer) bool {
pb := p.BoundingBox() pb := p.BoundingBox()
switch d := x.(type) { switch d := x.(type) {
case *Prism:
if p.pos.Z == d.pos.Z {
return p.pos.Y < d.pos.Y
}
return p.pos.Z > d.pos.Z
case BoundingBoxer: case BoundingBoxer:
xb := d.BoundingBox() xb := d.BoundingBox()
/*// No X overlap - no comparison needed
if pb.Max.X <= xb.Min.X || pb.Min.X >= xb.Max.X {
p.logue(x, "no x overlap")
return false
}*/
// Z ? // Z ?
if pb.Min.Z >= xb.Max.Z { // p is unambiguously in front if pb.Min.Z >= xb.Max.Z { // p is unambiguously in front
p.logue(x, "prism unambiguously in front")
return true return true
} }
if pb.Max.Z <= xb.Min.Z { // p is unambiguously behind if pb.Max.Z <= xb.Min.Z { // p is unambiguously behind
p.logue(x, "prism unambiguously behind")
return false return false
} }
// Y ? (NB: up is negative) // Y ? (NB: up is negative)
if pb.Max.Y <= xb.Min.Y { // p is above if pb.Max.Y <= xb.Min.Y { // p is above
p.logue(x, "prism unambiguously above")
return true return true
} }
if pb.Min.Y >= xb.Max.Y { // p is below if pb.Min.Y >= xb.Max.Y { // p is below
p.logue(x, "prism unambiguously below")
return false return false
} }
// Try Z again // The hexagon special
if pb.Min.Z+8 >= xb.Max.Z { if pb.Min.Z+8 >= xb.Max.Z {
p.logue(x, "prism midsection after max Z")
return true return true
} }
if pb.Min.Z+8 <= xb.Min.Z { if pb.Min.Z+8 <= xb.Min.Z {
p.logue(x, "prism midsection before min Z")
return false return false
} }
case zpositioner: case zpositioner:
p.logue(x, "zpositioner test??")
return pb.Min.Z > int(d.zposition()) return pb.Min.Z > int(d.zposition())
} }
p.logue(x, "no tests at all???")
return false return false
} }

View file

@ -45,10 +45,6 @@ func (s *Sprite) DrawAfter(x Drawer) bool {
switch d := x.(type) { switch d := x.(type) {
case BoundingBoxer: case BoundingBoxer:
xb := d.BoundingBox() xb := d.BoundingBox()
/*// No X overlap - no comparison needed
if sb.Max.X <= xb.Min.X || sb.Min.X >= xb.Max.X {
return false
}*/
// Z ? // Z ?
if sb.Min.Z >= xb.Max.Z { // s is unambiguously in front if sb.Min.Z >= xb.Max.Z { // s is unambiguously in front
return true return true
@ -63,6 +59,13 @@ func (s *Sprite) DrawAfter(x Drawer) bool {
if sb.Min.Y >= xb.Max.Y { // s is unambiguously below if sb.Min.Y >= xb.Max.Y { // s is unambiguously below
return false return false
} }
// Hexagon special
if sb.Min.Z > xb.Min.Z+8 {
return true
}
if sb.Max.Z < sb.Min.Z+8 {
return false
}
case zpositioner: case zpositioner:
return sb.Min.Z > int(d.zposition()) return sb.Min.Z > int(d.zposition())
} }