ichigo/engine/transform.go

37 lines
971 B
Go
Raw Normal View History

2021-09-03 09:42:50 +10:00
package engine
import (
"image"
"github.com/hajimehoshi/ebiten/v2"
)
// Transform is a bucket of things that affect drawing.
type Transform struct {
// IsoProjection is used by isometric 3D components to project their
// coordinates into 2D. There's usually only one component in the tree that
// sets this field, but it would apply to all descendants.
IsoProjection image.Point
// Opts contains the 2D geometry matrix, the colour matrix, filter mode, and
// composition mode.
Opts ebiten.DrawImageOptions
}
// Concat returns the combined transform (a transform equivalent to applying t
// and then u).
func (t Transform) Concat(u Transform) Transform {
if u.IsoProjection != (image.Point{}) {
t.IsoProjection = u.IsoProjection
}
t.Opts.ColorM.Concat(u.Opts.ColorM)
t.Opts.GeoM.Concat(u.Opts.GeoM)
if u.Opts.CompositeMode != 0 {
t.Opts.CompositeMode = u.Opts.CompositeMode
}
if u.Opts.Filter != 0 {
t.Opts.Filter = u.Opts.Filter
}
return t
}