mirror of
https://github.com/hajimehoshi/ebiten.git
synced 2024-12-24 18:58:54 +01:00
affine: Make Scale/Translate faster
This commit is contained in:
parent
48c8934838
commit
6e84919ed5
@ -106,7 +106,13 @@ func (c *ColorM) Add(other ColorM) {
|
||||
// Scale scales the matrix by (r, g, b, a).
|
||||
func (c *ColorM) Scale(r, g, b, a float64) {
|
||||
if c.elements == nil {
|
||||
c.elements = colorMIdentityElements
|
||||
c.elements = []float64{
|
||||
r, 0, 0, 0, 0,
|
||||
0, g, 0, 0, 0,
|
||||
0, 0, b, 0, 0,
|
||||
0, 0, 0, a, 0,
|
||||
}
|
||||
return
|
||||
}
|
||||
es := make([]float64, len(c.elements))
|
||||
copy(es, c.elements)
|
||||
@ -122,7 +128,13 @@ func (c *ColorM) Scale(r, g, b, a float64) {
|
||||
// Translate translates the matrix by (r, g, b, a).
|
||||
func (c *ColorM) Translate(r, g, b, a float64) {
|
||||
if c.elements == nil {
|
||||
c.elements = colorMIdentityElements
|
||||
c.elements = []float64{
|
||||
1, 0, 0, 0, r,
|
||||
0, 1, 0, 0, g,
|
||||
0, 0, 1, 0, b,
|
||||
0, 0, 0, 1, a,
|
||||
}
|
||||
return
|
||||
}
|
||||
es := make([]float64, len(c.elements))
|
||||
copy(es, c.elements)
|
||||
|
@ -81,7 +81,11 @@ func (g *GeoM) Add(other GeoM) {
|
||||
// Scale scales the matrix by (x, y).
|
||||
func (g *GeoM) Scale(x, y float64) {
|
||||
if g.elements == nil {
|
||||
g.elements = geoMIdentityElements
|
||||
g.elements = []float64{
|
||||
x, 0, 0,
|
||||
0, y, 0,
|
||||
}
|
||||
return
|
||||
}
|
||||
es := make([]float64, len(g.elements))
|
||||
copy(es, g.elements)
|
||||
@ -95,7 +99,11 @@ func (g *GeoM) Scale(x, y float64) {
|
||||
// Translate translates the matrix by (x, y).
|
||||
func (g *GeoM) Translate(tx, ty float64) {
|
||||
if g.elements == nil {
|
||||
g.elements = geoMIdentityElements
|
||||
g.elements = []float64{
|
||||
1, 0, tx,
|
||||
0, 1, ty,
|
||||
}
|
||||
return
|
||||
}
|
||||
es := make([]float64, len(g.elements))
|
||||
copy(es, g.elements)
|
||||
|
Loading…
Reference in New Issue
Block a user