affine: Add Reset function

This commit is contained in:
Hajime Hoshi 2017-05-25 22:50:47 +09:00
parent de7215f3fc
commit dad427920d
5 changed files with 19 additions and 1 deletions

View File

@ -33,6 +33,11 @@ type ColorM struct {
impl affine.ColorM impl affine.ColorM
} }
// Reset resets the ColorM as identity.
func (c *ColorM) Reset() {
c.impl.Reset()
}
// Concat multiplies a color matrix with the other color matrix. // Concat multiplies a color matrix with the other color matrix.
// This is same as muptiplying the matrix other and the matrix c in this order. // This is same as muptiplying the matrix other and the matrix c in this order.
func (c *ColorM) Concat(other ColorM) { func (c *ColorM) Concat(other ColorM) {

View File

@ -110,7 +110,7 @@ func update(screen *ebiten.Image) error {
} }
for i := 0; i < sprites.num; i++ { for i := 0; i < sprites.num; i++ {
s := sprites.sprites[i] s := sprites.sprites[i]
op.GeoM = ebiten.GeoM{} op.GeoM.Reset()
op.GeoM.Translate(float64(s.x), float64(s.y)) op.GeoM.Translate(float64(s.x), float64(s.y))
screen.DrawImage(ebitenImage, op) screen.DrawImage(ebitenImage, op)
} }

View File

@ -28,6 +28,11 @@ type GeoM struct {
impl affine.GeoM impl affine.GeoM
} }
// Reset resets the GeoM as identity.
func (g *GeoM) Reset() {
g.impl.Reset()
}
// Element returns a value of a matrix at (i, j). // Element returns a value of a matrix at (i, j).
func (g *GeoM) Element(i, j int) float64 { func (g *GeoM) Element(i, j int) float64 {
a, b, c, d, tx, ty := g.impl.Elements() a, b, c, d, tx, ty := g.impl.Elements()

View File

@ -44,6 +44,10 @@ type ColorM struct {
elements []float64 elements []float64
} }
func (c *ColorM) Reset() {
c.elements = nil
}
func (c *ColorM) UnsafeElements() []float64 { func (c *ColorM) UnsafeElements() []float64 {
if c.elements == nil { if c.elements == nil {
c.elements = colorMIdentityElements c.elements = colorMIdentityElements

View File

@ -34,6 +34,10 @@ type GeoM struct {
inited bool inited bool
} }
func (g *GeoM) Reset() {
g.inited = false
}
func (g *GeoM) Elements() (a, b, c, d, tx, ty float64) { func (g *GeoM) Elements() (a, b, c, d, tx, ty float64) {
if !g.inited { if !g.inited {
return 1, 0, 0, 1, 0, 0 return 1, 0, 0, 1, 0, 0