+{Elevation,Simple}Projection

This commit is contained in:
Josh Deprez 2021-09-23 10:13:05 +10:00
parent 4ce9a5b673
commit 8aa65bf08d
2 changed files with 22 additions and 8 deletions

View file

@ -16,10 +16,28 @@ func Project(π Projector, p Int3) image.Point {
return π.Project(p.Z).Add(p.XY()) return π.Project(p.Z).Add(p.XY())
} }
// Projection uses floats to define a projection. // ElevationProjection throws away Z.
type ElevationProjection struct{}
// Sign returns the zero point.
func (ElevationProjection) Sign() image.Point { return image.Point{} }
// Project returns the zero point.
func (ElevationProjection) Project(int) image.Point { return image.Point{} }
// SimpleProjection projects Z onto Y only.
type SimpleProjection struct{}
// Sign returns (0, 1).
func (SimpleProjection) Sign() image.Point { return image.Pt(0, 1) }
// Project returns (0, z).
func (SimpleProjection) Project(z int) image.Point { return image.Pt(0, z) }
// Projection uses two floats to define a custom projection.
type Projection struct{ X, Y float64 } type Projection struct{ X, Y float64 }
func (π Projection) Sign() (s image.Point) { func (π Projection) Sign() image.Point {
return image.Pt(int(FSign(π.X)), int(FSign(π.Y))) return image.Pt(int(FSign(π.X)), int(FSign(π.Y)))
} }
@ -31,7 +49,7 @@ func (π Projection) Project(z int) image.Point {
) )
} }
// IntProjection holds an integer projection definition. // IntProjection uses two integers to define a custom projection.
// It is designed for projecting Z onto X and Y with integer fractions as would // It is designed for projecting Z onto X and Y with integer fractions as would
// be used in e.g. a diametric projection (IntProjection{X:0, Y:2}). // be used in e.g. a diametric projection (IntProjection{X:0, Y:2}).
type IntProjection image.Point type IntProjection image.Point

View file

@ -56,11 +56,7 @@ func main() {
ScreenSize: image.Pt(320, 240), // Window interior is this many pixels. ScreenSize: image.Pt(320, 240), // Window interior is this many pixels.
// TODO: refactor Projection and VoxelScale into... Scene? Camera? // TODO: refactor Projection and VoxelScale into... Scene? Camera?
// We might want different projections and scales in different levels. // We might want different projections and scales in different levels.
Projection: geom.IntProjection{ Projection: geom.SimpleProjection{},
// Each 1 voxel step in Z is projected into 1 pixel in Y.
X: 0,
Y: 1,
},
VoxelScale: geom.Float3{ VoxelScale: geom.Float3{
// Each voxel counts for this much (Euclidean) space. // Each voxel counts for this much (Euclidean) space.
X: 1, X: 1,