Use new style methods of matrices

This commit is contained in:
Hajime Hoshi 2015-01-05 10:30:33 +09:00
parent 2be0aa7f0c
commit 4226354e4a
8 changed files with 45 additions and 52 deletions

View File

@ -49,10 +49,9 @@ func update(screen *ebiten.Image) error {
return err return err
} }
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
op := &ebiten.DrawImageOptions{ op := &ebiten.DrawImageOptions{}
GeoM: ebiten.TranslateGeo(15+float64(i)*diff, 20), op.GeoM.Translate(15+float64(i)*diff, 20)
ColorM: ebiten.ScaleColor(1.0, 1.0, 1.0, 0.5), op.ColorM.Scale(1.0, 1.0, 1.0, 0.5)
}
if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil { if err := tmpRenderTarget.DrawImage(ebitenImage, op); err != nil {
return err return err
} }
@ -60,9 +59,8 @@ func update(screen *ebiten.Image) error {
screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff}) screen.Fill(color.NRGBA{0x00, 0x00, 0x80, 0xff})
for i := 0; i < 10; i++ { for i := 0; i < 10; i++ {
op := &ebiten.DrawImageOptions{ op := &ebiten.DrawImageOptions{}
GeoM: ebiten.TranslateGeo(0, float64(i)*diff), op.GeoM.Translate(0, float64(i)*diff)
}
if err := screen.DrawImage(tmpRenderTarget, op); err != nil { if err := screen.DrawImage(tmpRenderTarget, op); err != nil {
return err return err
} }

View File

@ -56,12 +56,11 @@ func init() {
func drawRect(r *ebiten.Image, x, y, width, height int) error { func drawRect(r *ebiten.Image, x, y, width, height int) error {
w, h := imageEmpty.Size() w, h := imageEmpty.Size()
geo := ebiten.ScaleGeo(float64(width)/float64(w), float64(height)/float64(h)) op := &ebiten.DrawImageOptions{}
geo.Concat(ebiten.TranslateGeo(float64(x), float64(y))) op.GeoM.Scale(float64(width)/float64(w), float64(height)/float64(h))
return r.DrawImage(imageEmpty, &ebiten.DrawImageOptions{ op.GeoM.Translate(float64(x), float64(y))
GeoM: geo, op.ColorM.Scale(0.0, 0.0, 0.0, 0.75)
ColorM: ebiten.ScaleColor(0.0, 0.0, 0.0, 0.75), return r.DrawImage(imageEmpty, op)
})
} }
var fontColor = color.NRGBA{0x40, 0x40, 0xff, 0xff} var fontColor = color.NRGBA{0x40, 0x40, 0xff, 0xff}
@ -109,28 +108,25 @@ func (s *GameScene) drawBackground(r *ebiten.Image) error {
} }
w, h := imageGameBG.Size() w, h := imageGameBG.Size()
var geo ebiten.GeoM
geo.Translate(-float64(w)/2, -float64(h)/2)
scaleW := ScreenWidth / float64(w) scaleW := ScreenWidth / float64(w)
scaleH := ScreenHeight / float64(h) scaleH := ScreenHeight / float64(h)
scale := scaleW scale := scaleW
if scale < scaleH { if scale < scaleH {
scale = scaleH scale = scaleH
} }
geo.Scale(scale, scale)
geo.Translate(ScreenWidth/2, ScreenHeight/2) op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
op.GeoM.Scale(scale, scale)
op.GeoM.Translate(ScreenWidth/2, ScreenHeight/2)
a := 0.7 a := 0.7
m := ebiten.Monochrome() m := ebiten.Monochrome()
m.Scale(a, a, a, a) m.Scale(a, a, a, a)
var clr ebiten.ColorM op.ColorM.Scale(1-a, 1-a, 1-a, 1-a)
clr.Scale(1-a, 1-a, 1-a, 1-a) op.ColorM.Add(m)
clr.Add(m) op.ColorM.Translate(0.3, 0.3, 0.3, 0)
clr.Translate(0.3, 0.3, 0.3, 0) return r.DrawImage(imageGameBG, op)
return r.DrawImage(imageGameBG, &ebiten.DrawImageOptions{
GeoM: geo,
ColorM: clr,
})
} }
const fieldWidth = blockWidth * fieldBlockNumX const fieldWidth = blockWidth * fieldBlockNumX

View File

@ -35,12 +35,10 @@ var (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
count++ count++
w, h := gophersImage.Size() w, h := gophersImage.Size()
geo := ebiten.TranslateGeo(float64(screenWidth-w)/2, float64(screenHeight-h)/2) op := &ebiten.DrawImageOptions{}
clr := ebiten.RotateHue(float64(count%360) * 2 * math.Pi / 360) op.GeoM.Translate(float64(screenWidth-w)/2, float64(screenHeight-h)/2)
if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{ op.ColorM.Concat(ebiten.RotateHue(float64(count%360) * 2 * math.Pi / 360))
GeoM: geo, if err := screen.DrawImage(gophersImage, op); err != nil {
ColorM: clr,
}); err != nil {
return err return err
} }
return nil return nil

View File

@ -34,12 +34,12 @@ var (
) )
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
gophersRenderTarget.DrawImage(gophersImage, &ebiten.DrawImageOptions{ op := &ebiten.DrawImageOptions{}
GeoM: ebiten.ScaleGeo(1.0/mosaicRatio, 1.0/mosaicRatio), op.GeoM.Scale(1.0/mosaicRatio, 1.0/mosaicRatio)
}) gophersRenderTarget.DrawImage(gophersImage, op)
screen.DrawImage(gophersRenderTarget, &ebiten.DrawImageOptions{ op = &ebiten.DrawImageOptions{}
GeoM: ebiten.ScaleGeo(mosaicRatio, mosaicRatio), op.GeoM.Scale(mosaicRatio, mosaicRatio)
}) screen.DrawImage(gophersRenderTarget, op)
return nil return nil
} }

View File

@ -42,13 +42,12 @@ func Update(screen *ebiten.Image) error {
mx, my := ebiten.CursorPosition() mx, my := ebiten.CursorPosition()
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
clr := ebiten.ScaleColor(1.0, 0.25, 0.25, 1.0) op := &ebiten.DrawImageOptions{}
op.GeoM.Translate(float64(mx), float64(my))
op.ColorM.Scale(1.0, 0.25, 0.25, 1.0)
theta := 2.0 * math.Pi * float64(count%60) / 60.0 theta := 2.0 * math.Pi * float64(count%60) / 60.0
clr.Concat(ebiten.RotateHue(theta)) op.ColorM.Concat(ebiten.RotateHue(theta))
canvasRenderTarget.DrawImage(brushRenderTarget, &ebiten.DrawImageOptions{ canvasRenderTarget.DrawImage(brushRenderTarget, op)
GeoM: ebiten.TranslateGeo(float64(mx), float64(my)),
ColorM: clr,
})
} }
screen.DrawImage(canvasRenderTarget, nil) screen.DrawImage(canvasRenderTarget, nil)

View File

@ -35,12 +35,11 @@ var (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
count++ count++
w, h := gophersImage.Size() w, h := gophersImage.Size()
geo := ebiten.TranslateGeo(-float64(w)/2, -float64(h)/2) op := &ebiten.DrawImageOptions{}
geo.Concat(ebiten.RotateGeo(float64(count%360) * 2 * math.Pi / 360)) op.GeoM.Translate(-float64(w)/2, -float64(h)/2)
geo.Concat(ebiten.TranslateGeo(screenWidth/2, screenHeight/2)) op.GeoM.Rotate(float64(count%360) * 2 * math.Pi / 360)
if err := screen.DrawImage(gophersImage, &ebiten.DrawImageOptions{ op.GeoM.Translate(screenWidth/2, screenHeight/2)
GeoM: geo, if err := screen.DrawImage(gophersImage, op); err != nil {
}); err != nil {
return err return err
} }
return nil return nil

View File

@ -88,6 +88,10 @@ func (g *GeoM) Translate(tx, ty float64) {
g.es[1][2] += ty g.es[1][2] += ty
} }
func (g *GeoM) Rotate(theta float64) {
g.Concat(RotateGeo(theta))
}
// SetElement sets an element at (i, j). // SetElement sets an element at (i, j).
func (g *GeoM) SetElement(i, j int, element float64) { func (g *GeoM) SetElement(i, j int, element float64) {
if !g.initialized { if !g.initialized {

View File

@ -68,9 +68,8 @@ func (c *graphicsContext) postUpdate() error {
} }
scale := float64(c.screenScale) scale := float64(c.screenScale)
options := &DrawImageOptions{ options := &DrawImageOptions{}
GeoM: ScaleGeo(scale, scale), options.GeoM.Scale(scale, scale)
}
if err := c.defaultR.drawImage(c.glContext, c.screen, options); err != nil { if err := c.defaultR.drawImage(c.glContext, c.screen, options); err != nil {
return err return err
} }