ichigo/engine/projection.go

25 lines
691 B
Go
Raw Normal View History

2021-09-05 17:22:46 +10:00
package engine
2021-09-05 20:54:43 +10:00
var (
2021-09-05 17:22:46 +10:00
// Oblique projections
CabinetProjection = ParallelProjection{0.5, 0.5}
CavalierProjection = ParallelProjection{1, 1}
// Axonometric projections
ElevationProjection = ParallelProjection{0, 0}
2021-09-06 17:50:17 +10:00
DimetricProjection = ParallelProjection{0, 0.5}
HexPrismProjection = ParallelProjection{0, 0.577350269189626} // 1 ÷ √3
2021-09-05 17:22:46 +10:00
IsometricProjection = ParallelProjection{0, 0.707106781186548} // 1 ÷ √2
TrimetricProjection = ParallelProjection{0, 1}
)
type ParallelProjection struct {
ZX, ZY float64
}
func (π ParallelProjection) Project(p Point3) (px, py float64) {
px = float64(p.X) + π.ZX*float64(p.Z)
py = float64(p.Y) + π.ZY*float64(p.Z)
return px, py
}