Change GeometryMatrix's methods to functions

This commit is contained in:
Hajime Hoshi 2014-12-15 01:58:52 +09:00
parent d5f8e79c88
commit 2c67a71a53
8 changed files with 29 additions and 28 deletions

View File

@ -55,7 +55,7 @@ func (d *debugPrintState) drawText(gr ebiten.GraphicsContext, str string, x, y i
locationX += assets.TextImageCharWidth locationX += assets.TextImageCharWidth
} }
geom := ebiten.GeometryMatrixI() geom := ebiten.GeometryMatrixI()
geom.Translate(float64(x)+1, float64(y)) geom.Concat(ebiten.TranslateGeometry(float64(x)+1, float64(y)))
clrm := ebiten.ColorMatrixI() clrm := ebiten.ColorMatrixI()
clrm.Scale(clr) clrm.Scale(clr)
gr.Texture(d.textTexture).Draw(parts, geom, clrm) gr.Texture(d.textTexture).Draw(parts, geom, clrm)

View File

@ -56,8 +56,8 @@ func drawText(context ebiten.GraphicsContext, textures *Textures, str string, x,
} }
geoMat := ebiten.GeometryMatrixI() geoMat := ebiten.GeometryMatrixI()
geoMat.Scale(float64(scale), float64(scale)) geoMat.Concat(ebiten.ScaleGeometry(float64(scale), float64(scale)))
geoMat.Translate(float64(x), float64(y)) geoMat.Concat(ebiten.TranslateGeometry(float64(x), float64(y)))
clrMat := ebiten.ColorMatrixI() clrMat := ebiten.ColorMatrixI()
clrMat.Scale(clr) clrMat.Scale(clr)
context.Texture(fontTextureId).Draw(parts, geoMat, clrMat) context.Texture(fontTextureId).Draw(parts, geoMat, clrMat)

View File

@ -116,16 +116,14 @@ func (s *GameScene) Draw(context ebiten.GraphicsContext, textures *Textures) {
field := textures.GetTexture("empty") field := textures.GetTexture("empty")
geoMat := ebiten.GeometryMatrixI() geoMat := ebiten.GeometryMatrixI()
geoMat.Scale( geoMat.Concat(ebiten.ScaleGeometry(float64(fieldWidth)/float64(emptyWidth), float64(fieldHeight)/float64(emptyHeight)))
float64(fieldWidth)/float64(emptyWidth), geoMat.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number?
float64(fieldHeight)/float64(emptyHeight))
geoMat.Translate(20, 20) // magic number?
colorMat := ebiten.ColorMatrixI() colorMat := ebiten.ColorMatrixI()
colorMat.Scale(color.RGBA{0, 0, 0, 0x80}) colorMat.Scale(color.RGBA{0, 0, 0, 0x80})
ebiten.DrawWhole(context.Texture(field), emptyWidth, emptyHeight, geoMat, colorMat) ebiten.DrawWhole(context.Texture(field), emptyWidth, emptyHeight, geoMat, colorMat)
geoMat = ebiten.GeometryMatrixI() geoMat = ebiten.GeometryMatrixI()
geoMat.Translate(20, 20) geoMat.Concat(ebiten.TranslateGeometry(20, 20))
s.field.Draw(context, textures, geoMat) s.field.Draw(context, textures, geoMat)
if s.currentPiece != nil { if s.currentPiece != nil {

View File

@ -234,7 +234,7 @@ func (p *Piece) Draw(context ebiten.GraphicsContext, textures *Textures, fieldX,
geoMat := ebiten.GeometryMatrixI() geoMat := ebiten.GeometryMatrixI()
x := fieldX + pieceX*blockWidth x := fieldX + pieceX*blockWidth
y := fieldY + pieceY*blockHeight y := fieldY + pieceY*blockHeight
geoMat.Translate(float64(x), float64(y)) geoMat.Concat(ebiten.TranslateGeometry(float64(x), float64(y)))
drawBlocks(context, textures, blocks, geoMat) drawBlocks(context, textures, blocks, geoMat)
} }

View File

@ -69,7 +69,7 @@ func drawTitleBackground(context ebiten.GraphicsContext, textures *Textures, c i
dx := (-c / 4) % textureWidth dx := (-c / 4) % textureWidth
dy := (c / 4) % textureHeight dy := (c / 4) % textureHeight
geo := ebiten.GeometryMatrixI() geo := ebiten.GeometryMatrixI()
geo.Translate(float64(dx), float64(dy)) geo.Concat(ebiten.TranslateGeometry(float64(dx), float64(dy)))
clr := ebiten.ColorMatrixI() clr := ebiten.ColorMatrixI()
context.Texture(backgroundTextureId).Draw(parts, geo, clr) context.Texture(backgroundTextureId).Draw(parts, geo, clr)
} }

View File

@ -55,7 +55,7 @@ func (g *Game) Draw(gr ebiten.GraphicsContext) error {
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) { if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
gr.PushRenderTarget(g.canvasRenderTarget) gr.PushRenderTarget(g.canvasRenderTarget)
geo := ebiten.GeometryMatrixI() geo := ebiten.GeometryMatrixI()
geo.Translate(float64(mx), float64(my)) geo.Concat(ebiten.TranslateGeometry(float64(mx), float64(my)))
clr := ebiten.ColorMatrixI() clr := ebiten.ColorMatrixI()
clr.Scale(color.RGBA{0xff, 0xff, 0x00, 0xff}) clr.Scale(color.RGBA{0xff, 0xff, 0x00, 0xff})
theta := 2.0 * math.Pi * float64(g.count%60) / 60.0 theta := 2.0 * math.Pi * float64(g.count%60) / 60.0

View File

@ -63,30 +63,33 @@ func (g *GeometryMatrix) setElement(i, j int, element float64) {
g.Elements[i][j] = element g.Elements[i][j] = element
} }
// Translate translates the geometry matrix by (tx, ty). // ScaleGeometry returns a matrix that scales a geometry matrix by (x, y).
func (g *GeometryMatrix) Translate(tx, ty float64) { func ScaleGeometry(x, y float64) GeometryMatrix {
g.Elements[0][2] += tx return GeometryMatrix{
g.Elements[1][2] += ty [2][3]float64{
{x, 0, 0},
{0, y, 0},
},
}
} }
// Scale scales the geometry matrix by (x, y). // TranslateGeometry returns a matrix taht translates a geometry matrix by (tx, ty).
func (g *GeometryMatrix) Scale(x, y float64) { func TranslateGeometry(tx, ty float64) GeometryMatrix {
g.Elements[0][0] *= x return GeometryMatrix{
g.Elements[0][1] *= x [2][3]float64{
g.Elements[0][2] *= x {1, 0, tx},
g.Elements[1][0] *= y {0, 1, ty},
g.Elements[1][1] *= y },
g.Elements[1][2] *= y }
} }
// Rotate rotates the geometry matrix by theta. // RotateGeometry returns a matrix that rotates a geometry matrix by theta.
func (g *GeometryMatrix) Rotate(theta float64) { func RotateGeometry(theta float64) GeometryMatrix {
sin, cos := math.Sincos(theta) sin, cos := math.Sincos(theta)
rotate := GeometryMatrix{ return GeometryMatrix{
[2][3]float64{ [2][3]float64{
{cos, -sin, 0}, {cos, -sin, 0},
{sin, cos, 0}, {sin, cos, 0},
}, },
} }
g.Concat(rotate)
} }

View File

@ -101,7 +101,7 @@ func (c *graphicsContext) postUpdate() {
scale := float64(c.screenScale) scale := float64(c.screenScale)
geo := GeometryMatrixI() geo := GeometryMatrixI()
geo.Scale(scale, scale) geo.Concat(ScaleGeometry(scale, scale))
DrawWhole(c.RenderTarget(c.screenID), c.screenWidth, c.screenHeight, geo, ColorMatrixI()) DrawWhole(c.RenderTarget(c.screenID), c.screenWidth, c.screenHeight, geo, ColorMatrixI())
gl.Flush() gl.Flush()