world view ray casting

This commit is contained in:
2022-02-22 14:28:59 +08:00
parent 3595c32ae5
commit c2a69d7cd0
5 changed files with 170 additions and 1 deletions

View File

@@ -23,7 +23,8 @@ type BlockAppearance struct {
NotSolid bool // Is block not solid, i.e., has no hitbox at all? (this makes the zero value reasonable)
Light int // The light level it emits, 0 is none
Hitbox []itype.Boxd // Hitbox, in block-local coordinates; empty slice means a default hitbox of 1x1x1
Hitbox []itype.Boxd // Hitbox, in block-local coordinates; empty slice means a default hitbox of 1x1x1
Lookbox []itype.Boxd // Selection hitbox, hit only by the view ray; empty means Hitbox[]
RenderType BlockRenderType // Rendering type, defaults to OneTexture (zero value)
@@ -130,6 +131,9 @@ func GetBlockAppearance(position itype.Vec3i, id, aux int, data itype.Dataset, w
SizeX: 1, SizeY: 1, SizeZ: 1,
}}
}
if len(app.Lookbox) == 0 {
app.Lookbox = app.Hitbox
}
return app
}
@@ -146,6 +150,9 @@ func GetBlockAppearance(position itype.Vec3i, id, aux int, data itype.Dataset, w
SizeX: 1, SizeY: 1, SizeZ: 1,
}}
}
if len(app.Lookbox) == 0 {
app.Lookbox = app.Hitbox
}
return app
}
@@ -172,6 +179,16 @@ func (b Block) Appearance(position itype.Vec3i) BlockAppearance {
SizeX: 1, SizeY: 1, SizeZ: 1,
}}
}
if len(app.Lookbox) == 0 {
if len(app.Hitbox) == 0 {
app.Lookbox = []itype.Boxd{{
OffX: 0, OffY: 0, OffZ: 0,
SizeX: 1, SizeY: 1, SizeZ: 1,
}}
} else {
app.Lookbox = app.Hitbox
}
}
return app
}