gg/src/gx/transform.go

36 lines
574 B
Go
Raw Normal View History

2023-02-17 12:47:17 +03:00
package gx
2023-02-17 23:51:40 +03:00
import (
//"github.com/hajimehoshi/ebiten/v2"
//"math"
2023-02-17 23:51:40 +03:00
)
2023-02-17 12:47:17 +03:00
type Transform struct {
// Position, scale, rotate around(relatively of position, not absolute).
2023-02-17 12:47:17 +03:00
P, S, RA Vector
// Rotation angle in radians.
R Float
}
// Returns empty Transform.
2023-02-17 12:47:17 +03:00
func T() Transform {
2023-05-22 23:51:14 +03:00
ret := Transform{
S: Vector{1, 1},
}
2023-02-17 12:47:17 +03:00
return ret
}
2023-02-17 23:51:40 +03:00
// Returns the GeoM with corresponding
// to the transfrom transformation.
2023-05-30 14:34:10 +03:00
func (t Transform)Matrix() Matrix {
2023-02-17 23:51:40 +03:00
g := &Matrix{}
g.Scale(t.S.X, t.S.Y)
2023-02-18 02:03:28 +03:00
g.Translate(-t.RA.X, -t.RA.Y)
2023-02-17 23:51:40 +03:00
g.Rotate(t.R)
g.Translate(t.P.X, t.P.Y)
2023-02-17 23:51:40 +03:00
return *g
}