Transform now responsible for concat
This commit is contained in:
parent
e065bad1a7
commit
88ded18d50
9 changed files with 40 additions and 21 deletions
|
@ -36,7 +36,7 @@ func (b *Billboard) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
// Scan returns a slice containing Src.
|
// Scan returns a slice containing Src.
|
||||||
func (b *Billboard) Scan() []interface{} { return []interface{}{&b.Src} }
|
func (b *Billboard) Scan() []interface{} { return []interface{}{&b.Src} }
|
||||||
|
|
||||||
func (b *Billboard) Transform() (tf Transform) {
|
func (b *Billboard) Transform(pt Transform) (tf Transform) {
|
||||||
tf.Opts.GeoM.Translate(cfloat(b.Pos))
|
tf.Opts.GeoM.Translate(cfloat(b.Pos))
|
||||||
return tf
|
return tf.Concat(pt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,11 +85,11 @@ func (c *Camera) Prepare(game *Game) error {
|
||||||
func (c *Camera) Scan() []interface{} { return []interface{}{c.Child} }
|
func (c *Camera) Scan() []interface{} { return []interface{}{c.Child} }
|
||||||
|
|
||||||
// Transform returns the camera transform.
|
// Transform returns the camera transform.
|
||||||
func (c *Camera) Transform() (tf Transform) {
|
func (c *Camera) Transform(pt Transform) (tf Transform) {
|
||||||
tf.IsoProjection = c.IsoProjection
|
tf.IsoProjection = c.IsoProjection
|
||||||
tf.Opts.GeoM.Translate(cfloat(c.Centre.Mul(-1)))
|
tf.Opts.GeoM.Translate(cfloat(c.Centre.Mul(-1)))
|
||||||
tf.Opts.GeoM.Scale(c.Zoom, c.Zoom)
|
tf.Opts.GeoM.Scale(c.Zoom, c.Zoom)
|
||||||
tf.Opts.GeoM.Rotate(c.Rotation)
|
tf.Opts.GeoM.Rotate(c.Rotation)
|
||||||
tf.Opts.GeoM.Translate(cfloat(c.game.ScreenSize.Div(2)))
|
tf.Opts.GeoM.Translate(cfloat(c.game.ScreenSize.Div(2)))
|
||||||
return tf
|
return tf.Concat(pt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,8 +96,8 @@ func (g *Game) Draw(screen *ebiten.Image) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// p is not hidden, so compute its cumulative transform.
|
// p is not hidden, so compute its cumulative transform.
|
||||||
if t, ok := p.(Transformer); ok {
|
if tf, ok := p.(Transformer); ok {
|
||||||
st.transform = t.Transform().Concat(st.transform)
|
st.transform = tf.Transform(st.transform)
|
||||||
}
|
}
|
||||||
accum[p] = st
|
accum[p] = st
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,9 +105,17 @@ type Saver interface {
|
||||||
Save() error
|
Save() error
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transformer components can transform their child components.
|
// Transformer components can provide a transform to apply to themselves and any
|
||||||
|
// child components, based on the cumulative parent transform. An
|
||||||
|
// example implementation:
|
||||||
|
//
|
||||||
|
// func (f Foo) Transform(pt Transform) Transform {
|
||||||
|
// var tf Transform
|
||||||
|
// tf.Opts.GeoM.Translate(-2, 3) // or your own transform
|
||||||
|
// return tf.Concat(pt)
|
||||||
|
// }
|
||||||
type Transformer interface {
|
type Transformer interface {
|
||||||
Transform() Transform
|
Transform(Transform) Transform
|
||||||
}
|
}
|
||||||
|
|
||||||
// Updater components can update themselves. Update is called repeatedly. Each
|
// Updater components can update themselves. Update is called repeatedly. Each
|
||||||
|
|
|
@ -17,6 +17,7 @@ var (
|
||||||
_ interface {
|
_ interface {
|
||||||
Prepper
|
Prepper
|
||||||
Scanner
|
Scanner
|
||||||
|
Transformer
|
||||||
} = &IsoVoxel{}
|
} = &IsoVoxel{}
|
||||||
|
|
||||||
_ Drawer = &IsoVoxelSide{}
|
_ Drawer = &IsoVoxelSide{}
|
||||||
|
@ -61,9 +62,9 @@ func (m *IsoVoxmap) Scan() []interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform returns a translation by DrawOffset.
|
// Transform returns a translation by DrawOffset.
|
||||||
func (m *IsoVoxmap) Transform() (tf Transform) {
|
func (m *IsoVoxmap) Transform(pt Transform) (tf Transform) {
|
||||||
tf.Opts.GeoM.Translate(cfloat(m.DrawOffset))
|
tf.Opts.GeoM.Translate(cfloat(m.DrawOffset))
|
||||||
return tf
|
return tf.Concat(pt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsoVoxel is a voxel in an IsoVoxmap.
|
// IsoVoxel is a voxel in an IsoVoxmap.
|
||||||
|
@ -90,6 +91,14 @@ func (v *IsoVoxel) Scan() []interface{} {
|
||||||
return []interface{}{&v.back, &v.front}
|
return []interface{}{&v.back, &v.front}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Transform returns a translation the isoprojected coordinate of this voxel.
|
||||||
|
func (v *IsoVoxel) Transform(pt Transform) (tf Transform) {
|
||||||
|
tf.Opts.GeoM.Translate(cfloat(
|
||||||
|
v.pos.CMul(v.ivm.VoxSize).IsoProject(pt.IsoProjection),
|
||||||
|
))
|
||||||
|
return tf.Concat(pt)
|
||||||
|
}
|
||||||
|
|
||||||
// IsoVoxelSide is a side of a voxel.
|
// IsoVoxelSide is a side of a voxel.
|
||||||
type IsoVoxelSide struct {
|
type IsoVoxelSide struct {
|
||||||
front bool
|
front bool
|
||||||
|
|
|
@ -39,8 +39,8 @@ func (p *Parallax) Prepare(game *Game) error {
|
||||||
func (p *Parallax) Scan() []interface{} { return []interface{}{p.Child} }
|
func (p *Parallax) Scan() []interface{} { return []interface{}{p.Child} }
|
||||||
|
|
||||||
// Transform returns a GeoM translation of Factor * camera.Centre.
|
// Transform returns a GeoM translation of Factor * camera.Centre.
|
||||||
func (p *Parallax) Transform() (tf Transform) {
|
func (p *Parallax) Transform(pt Transform) (tf Transform) {
|
||||||
x, y := cfloat(p.camera.Centre)
|
x, y := cfloat(p.camera.Centre)
|
||||||
tf.Opts.GeoM.Translate(x*p.Factor, y*p.Factor)
|
tf.Opts.GeoM.Translate(x*p.Factor, y*p.Factor)
|
||||||
return tf
|
return tf.Concat(pt)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,9 +57,9 @@ func (s *Sprite) SetAnim(a *Anim) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform returns a translation by the FrameOffset.
|
// Transform returns a translation by the FrameOffset.
|
||||||
func (s *Sprite) Transform() (tf Transform) {
|
func (s *Sprite) Transform(pt Transform) (tf Transform) {
|
||||||
tf.Opts.GeoM.Translate(cfloat(s.Actor.Pos.XY().Add(s.FrameOffset)))
|
tf.Opts.GeoM.Translate(cfloat(s.Actor.Pos.XY().Add(s.FrameOffset)))
|
||||||
return tf
|
return tf.Concat(pt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update updates the Sprite's anim. anim can change a bit so we don't tell Game
|
// Update updates the Sprite's anim. anim can change a bit so we don't tell Game
|
||||||
|
|
|
@ -110,9 +110,9 @@ func (t *Tilemap) Scan() []interface{} {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform returns a translation by t.Offset.
|
// Transform returns a translation by t.Offset.
|
||||||
func (t *Tilemap) Transform() (tf Transform) {
|
func (t *Tilemap) Transform(pt Transform) (tf Transform) {
|
||||||
tf.Opts.GeoM.Translate(cfloat(t.Offset))
|
tf.Opts.GeoM.Translate(cfloat(t.Offset))
|
||||||
return tf
|
return tf.Concat(pt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TileAt returns the tile present at the given world coordinate.
|
// TileAt returns the tile present at the given world coordinate.
|
||||||
|
|
|
@ -80,9 +80,9 @@ func (w *Wall) Prepare(*Game) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transform returns a GeoM translation by Offset.
|
// Transform returns a GeoM translation by Offset.
|
||||||
func (w *Wall) Transform() (tf Transform) {
|
func (w *Wall) Transform(pt Transform) (tf Transform) {
|
||||||
tf.Opts.GeoM.Translate(cfloat(w.Offset))
|
tf.Opts.GeoM.Translate(cfloat(w.Offset))
|
||||||
return tf
|
return tf.Concat(pt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WallUnit is a unit in a wall. Unlike a tile in a tilemap, WallUnit is
|
// WallUnit is a unit in a wall. Unlike a tile in a tilemap, WallUnit is
|
||||||
|
@ -105,7 +105,9 @@ func (u *WallUnit) Draw(screen *ebiten.Image, opts *ebiten.DrawImageOptions) {
|
||||||
// Scan returns the Tile.
|
// Scan returns the Tile.
|
||||||
func (u *WallUnit) Scan() []interface{} { return []interface{}{u.Tile} }
|
func (u *WallUnit) Scan() []interface{} { return []interface{}{u.Tile} }
|
||||||
|
|
||||||
func (u *WallUnit) Transform() (tf Transform) {
|
func (u *WallUnit) Transform(pt Transform) (tf Transform) {
|
||||||
tf.Opts.GeoM.Translate(cfloat(cmul(u.pos, u.wall.UnitSize).Add(u.wall.UnitOffset)))
|
tf.Opts.GeoM.Translate(cfloat(
|
||||||
return tf
|
cmul(u.pos, u.wall.UnitSize).Add(u.wall.UnitOffset),
|
||||||
|
))
|
||||||
|
return tf.Concat(pt)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue