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

View File

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

View File

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

View File

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

View File

@ -42,13 +42,12 @@ func Update(screen *ebiten.Image) error {
mx, my := ebiten.CursorPosition()
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
clr.Concat(ebiten.RotateHue(theta))
canvasRenderTarget.DrawImage(brushRenderTarget, &ebiten.DrawImageOptions{
GeoM: ebiten.TranslateGeo(float64(mx), float64(my)),
ColorM: clr,
})
op.ColorM.Concat(ebiten.RotateHue(theta))
canvasRenderTarget.DrawImage(brushRenderTarget, op)
}
screen.DrawImage(canvasRenderTarget, nil)

View File

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

View File

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

View File

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