WIP: committing some ideas
This commit is contained in:
parent
25f4f29e1b
commit
d1e88311de
5 changed files with 79 additions and 12 deletions
Binary file not shown.
60
engine/matrix.go
Normal file
60
engine/matrix.go
Normal file
|
@ -0,0 +1,60 @@
|
|||
package engine
|
||||
|
||||
import "image"
|
||||
|
||||
// IntMatrix3 implements a 3x3 integer matrix.
|
||||
type IntMatrix3 [3][3]int
|
||||
|
||||
// Apply applies the matrix to a vector to obtain a transformed vector.
|
||||
func (a IntMatrix3) Apply(v Point3) Point3 {
|
||||
return Point3{
|
||||
X: v.X*a[0][0] + v.Y*a[0][1] + v.Z*a[0][2],
|
||||
Y: v.X*a[1][0] + v.Y*a[1][1] + v.Z*a[1][2],
|
||||
Z: v.X*a[2][0] + v.Y*a[2][1] + v.Z*a[2][2],
|
||||
}
|
||||
}
|
||||
|
||||
// Concat returns the matrix equivalent to applying matrix a and then b.
|
||||
func (a IntMatrix3) Concat(b IntMatrix3) IntMatrix3 {
|
||||
return IntMatrix3{
|
||||
[3]int{
|
||||
a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0],
|
||||
a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1],
|
||||
a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2],
|
||||
},
|
||||
[3]int{
|
||||
a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0],
|
||||
a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1],
|
||||
a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2],
|
||||
},
|
||||
[3]int{
|
||||
a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0],
|
||||
a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1],
|
||||
a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2],
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// IntMatrix3x4 implements a 3 row, 4 column integer matrix, capable of
|
||||
//describing any integer affine transformation.
|
||||
type IntMatrix3x4 [3][4]int
|
||||
|
||||
// Apply applies the matrix to a vector to obtain a transformed vector.
|
||||
func (a IntMatrix3x4) Apply(v Point3) Point3 {
|
||||
return Point3{
|
||||
X: v.X*a[0][0] + v.Y*a[0][1] + v.Z*a[0][2] + a[0][3],
|
||||
Y: v.X*a[1][0] + v.Y*a[1][1] + v.Z*a[1][2] + a[1][3],
|
||||
Z: v.X*a[2][0] + v.Y*a[2][1] + v.Z*a[2][2] + a[2][3],
|
||||
}
|
||||
}
|
||||
|
||||
// IntMatrix2x3 implements a 2 row, 3 column matrix (as two Point3 row vectors).
|
||||
type IntMatrix2x3 [2]Point3
|
||||
|
||||
// Apply applies the matrix to a vector to obtain a transformed vector.
|
||||
func (a IntMatrix2x3) Apply(v Point3) image.Point {
|
||||
return image.Point{
|
||||
X: v.Dot(a[0]),
|
||||
Y: v.Dot(a[1]),
|
||||
}
|
||||
}
|
|
@ -70,6 +70,11 @@ func (p Point3) Sign() Point3 {
|
|||
return Point3{sign(p.X), sign(p.Y), sign(p.Z)}
|
||||
}
|
||||
|
||||
// Dot returns the dot product of the two vectors.
|
||||
func (p Point3) Dot(q Point3) int {
|
||||
return p.X*q.X + p.Y*q.Y + p.Z*q.Z
|
||||
}
|
||||
|
||||
func sign(m int) int {
|
||||
if m == 0 {
|
||||
return 0
|
||||
|
|
|
@ -33,16 +33,19 @@ type PrismMap struct {
|
|||
Disabled
|
||||
Hidden
|
||||
|
||||
Map map[Point3]*Prism // pos -> prism
|
||||
DrawOrderBias image.Point // dot with pos.XY() = bias value
|
||||
DrawOffset image.Point // offset applies to whole map
|
||||
DrawZStride image.Point // draw offset for each pos unit in Z
|
||||
PrismSize Point3 // (prismsize cmul pos) = world position
|
||||
Map map[Point3]*Prism // pos -> prism
|
||||
DrawOrderBias image.Point // dot with pos.XY() = bias value
|
||||
DrawOffset image.Point // offset applies to whole map
|
||||
PosToDraw IntMatrix2x3 // p.pos -> drawspace (before offset and camera and ...)
|
||||
PosToWorld IntMatrix3x4 // p.pos -> worldspace
|
||||
PrismSize Point3 // in worldspace
|
||||
Sheet Sheet
|
||||
}
|
||||
|
||||
func (m *PrismMap) CollidesWith(b Box) bool {
|
||||
// TODO
|
||||
// Back corner of a prism p is:
|
||||
// m.PrismPos.Apply(p.pos)
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -71,14 +74,13 @@ func (p *Prism) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
|||
}
|
||||
|
||||
func (p *Prism) DrawOrder() (int, int) {
|
||||
return p.pos.Z * p.pm.PrismSize.Z,
|
||||
return p.pm.PosToWorld.Apply(p.pos).Z,
|
||||
dot(p.pos.XY(), p.pm.DrawOrderBias)
|
||||
}
|
||||
|
||||
func (p *Prism) Transform(pt Transform) (tf Transform) {
|
||||
tf.Opts.GeoM.Translate(cfloat(
|
||||
cmul(p.pos.XY(), p.pm.PrismSize.XY()).
|
||||
Add(p.pm.DrawZStride.Mul(p.pos.Z)),
|
||||
p.pm.PosToDraw.Apply(p.pos),
|
||||
))
|
||||
return tf.Concat(pt)
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ var (
|
|||
CavalierProjection = ParallelProjection{1, 1}
|
||||
|
||||
// Axonometric projections
|
||||
DimetricProjection = ParallelProjection{0, 0.5}
|
||||
ElevationProjection = ParallelProjection{0, 0}
|
||||
DimetricProjection = ParallelProjection{0, 0.5}
|
||||
HexPrismProjection = ParallelProjection{0, 0.577350269189626} // 1 ÷ √3
|
||||
IsometricProjection = ParallelProjection{0, 0.707106781186548} // 1 ÷ √2
|
||||
TrimetricProjection = ParallelProjection{0, 1}
|
||||
HexPrismProjection = ParallelProjection{0, 0.816496580927726} // √2 ÷ √3
|
||||
)
|
||||
|
||||
type ParallelProjection struct {
|
||||
|
|
Loading…
Reference in a new issue