mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2025-01-12 12:08:58 +01:00
Change GeometryMatrix's methods to functions
This commit is contained in:
parent
d5f8e79c88
commit
2c67a71a53
@ -55,7 +55,7 @@ func (d *debugPrintState) drawText(gr ebiten.GraphicsContext, str string, x, y i
|
||||
locationX += assets.TextImageCharWidth
|
||||
}
|
||||
geom := ebiten.GeometryMatrixI()
|
||||
geom.Translate(float64(x)+1, float64(y))
|
||||
geom.Concat(ebiten.TranslateGeometry(float64(x)+1, float64(y)))
|
||||
clrm := ebiten.ColorMatrixI()
|
||||
clrm.Scale(clr)
|
||||
gr.Texture(d.textTexture).Draw(parts, geom, clrm)
|
||||
|
@ -56,8 +56,8 @@ func drawText(context ebiten.GraphicsContext, textures *Textures, str string, x,
|
||||
}
|
||||
|
||||
geoMat := ebiten.GeometryMatrixI()
|
||||
geoMat.Scale(float64(scale), float64(scale))
|
||||
geoMat.Translate(float64(x), float64(y))
|
||||
geoMat.Concat(ebiten.ScaleGeometry(float64(scale), float64(scale)))
|
||||
geoMat.Concat(ebiten.TranslateGeometry(float64(x), float64(y)))
|
||||
clrMat := ebiten.ColorMatrixI()
|
||||
clrMat.Scale(clr)
|
||||
context.Texture(fontTextureId).Draw(parts, geoMat, clrMat)
|
||||
|
@ -116,16 +116,14 @@ func (s *GameScene) Draw(context ebiten.GraphicsContext, textures *Textures) {
|
||||
|
||||
field := textures.GetTexture("empty")
|
||||
geoMat := ebiten.GeometryMatrixI()
|
||||
geoMat.Scale(
|
||||
float64(fieldWidth)/float64(emptyWidth),
|
||||
float64(fieldHeight)/float64(emptyHeight))
|
||||
geoMat.Translate(20, 20) // magic number?
|
||||
geoMat.Concat(ebiten.ScaleGeometry(float64(fieldWidth)/float64(emptyWidth), float64(fieldHeight)/float64(emptyHeight)))
|
||||
geoMat.Concat(ebiten.TranslateGeometry(20, 20)) // TODO: magic number?
|
||||
colorMat := ebiten.ColorMatrixI()
|
||||
colorMat.Scale(color.RGBA{0, 0, 0, 0x80})
|
||||
ebiten.DrawWhole(context.Texture(field), emptyWidth, emptyHeight, geoMat, colorMat)
|
||||
|
||||
geoMat = ebiten.GeometryMatrixI()
|
||||
geoMat.Translate(20, 20)
|
||||
geoMat.Concat(ebiten.TranslateGeometry(20, 20))
|
||||
s.field.Draw(context, textures, geoMat)
|
||||
|
||||
if s.currentPiece != nil {
|
||||
|
@ -234,7 +234,7 @@ func (p *Piece) Draw(context ebiten.GraphicsContext, textures *Textures, fieldX,
|
||||
geoMat := ebiten.GeometryMatrixI()
|
||||
x := fieldX + pieceX*blockWidth
|
||||
y := fieldY + pieceY*blockHeight
|
||||
geoMat.Translate(float64(x), float64(y))
|
||||
geoMat.Concat(ebiten.TranslateGeometry(float64(x), float64(y)))
|
||||
|
||||
drawBlocks(context, textures, blocks, geoMat)
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ func drawTitleBackground(context ebiten.GraphicsContext, textures *Textures, c i
|
||||
dx := (-c / 4) % textureWidth
|
||||
dy := (c / 4) % textureHeight
|
||||
geo := ebiten.GeometryMatrixI()
|
||||
geo.Translate(float64(dx), float64(dy))
|
||||
geo.Concat(ebiten.TranslateGeometry(float64(dx), float64(dy)))
|
||||
clr := ebiten.ColorMatrixI()
|
||||
context.Texture(backgroundTextureId).Draw(parts, geo, clr)
|
||||
}
|
||||
|
@ -55,7 +55,7 @@ func (g *Game) Draw(gr ebiten.GraphicsContext) error {
|
||||
if ebiten.IsMouseButtonPressed(ebiten.MouseButtonLeft) {
|
||||
gr.PushRenderTarget(g.canvasRenderTarget)
|
||||
geo := ebiten.GeometryMatrixI()
|
||||
geo.Translate(float64(mx), float64(my))
|
||||
geo.Concat(ebiten.TranslateGeometry(float64(mx), float64(my)))
|
||||
clr := ebiten.ColorMatrixI()
|
||||
clr.Scale(color.RGBA{0xff, 0xff, 0x00, 0xff})
|
||||
theta := 2.0 * math.Pi * float64(g.count%60) / 60.0
|
||||
|
@ -63,30 +63,33 @@ func (g *GeometryMatrix) setElement(i, j int, element float64) {
|
||||
g.Elements[i][j] = element
|
||||
}
|
||||
|
||||
// Translate translates the geometry matrix by (tx, ty).
|
||||
func (g *GeometryMatrix) Translate(tx, ty float64) {
|
||||
g.Elements[0][2] += tx
|
||||
g.Elements[1][2] += ty
|
||||
// ScaleGeometry returns a matrix that scales a geometry matrix by (x, y).
|
||||
func ScaleGeometry(x, y float64) GeometryMatrix {
|
||||
return GeometryMatrix{
|
||||
[2][3]float64{
|
||||
{x, 0, 0},
|
||||
{0, y, 0},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Scale scales the geometry matrix by (x, y).
|
||||
func (g *GeometryMatrix) Scale(x, y float64) {
|
||||
g.Elements[0][0] *= x
|
||||
g.Elements[0][1] *= x
|
||||
g.Elements[0][2] *= x
|
||||
g.Elements[1][0] *= y
|
||||
g.Elements[1][1] *= y
|
||||
g.Elements[1][2] *= y
|
||||
// TranslateGeometry returns a matrix taht translates a geometry matrix by (tx, ty).
|
||||
func TranslateGeometry(tx, ty float64) GeometryMatrix {
|
||||
return GeometryMatrix{
|
||||
[2][3]float64{
|
||||
{1, 0, tx},
|
||||
{0, 1, ty},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Rotate rotates the geometry matrix by theta.
|
||||
func (g *GeometryMatrix) Rotate(theta float64) {
|
||||
// RotateGeometry returns a matrix that rotates a geometry matrix by theta.
|
||||
func RotateGeometry(theta float64) GeometryMatrix {
|
||||
sin, cos := math.Sincos(theta)
|
||||
rotate := GeometryMatrix{
|
||||
return GeometryMatrix{
|
||||
[2][3]float64{
|
||||
{cos, -sin, 0},
|
||||
{sin, cos, 0},
|
||||
},
|
||||
}
|
||||
g.Concat(rotate)
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ func (c *graphicsContext) postUpdate() {
|
||||
|
||||
scale := float64(c.screenScale)
|
||||
geo := GeometryMatrixI()
|
||||
geo.Scale(scale, scale)
|
||||
geo.Concat(ScaleGeometry(scale, scale))
|
||||
DrawWhole(c.RenderTarget(c.screenID), c.screenWidth, c.screenHeight, geo, ColorMatrixI())
|
||||
|
||||
gl.Flush()
|
||||
|
Loading…
Reference in New Issue
Block a user