2023-10-23 15:45:18 +03:00
|
|
|
package gg
|
2023-02-17 12:47:17 +03:00
|
|
|
|
2023-02-17 23:51:40 +03:00
|
|
|
import (
|
2023-05-11 12:28:34 +03:00
|
|
|
//"github.com/hajimehoshi/ebiten/v2"
|
|
|
|
//"math"
|
2023-02-17 23:51:40 +03:00
|
|
|
)
|
|
|
|
|
2023-06-03 10:39:15 +03:00
|
|
|
// The structure represents basic transformation
|
|
|
|
// features: positioning, rotating and scaling.
|
2023-02-17 12:47:17 +03:00
|
|
|
type Transform struct {
|
2023-06-03 10:39:15 +03:00
|
|
|
// P - absolute phisycal position in engine itself.
|
|
|
|
//
|
|
|
|
// S - scale width and height (X and Y).
|
|
|
|
//
|
|
|
|
// RA - rotate around(relatively of position, not absolute).
|
|
|
|
//
|
|
|
|
// For example RA=Vector{0, 0} will rotate around right up corner
|
|
|
|
// and RA=Vector{.5, .5} will rotate around center.
|
2023-02-17 12:47:17 +03:00
|
|
|
P, S, RA Vector
|
|
|
|
// Rotation angle in radians.
|
|
|
|
R Float
|
|
|
|
}
|
|
|
|
|
2023-05-11 12:28:34 +03:00
|
|
|
// 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-06-03 10:39:15 +03:00
|
|
|
func (t Transform) ScaledToXY(x, y Float) Transform {
|
|
|
|
return t.ScaledToX(x).ScaledToY(y)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t Transform) ScaledToX(x Float) Transform {
|
|
|
|
t.S.X = x
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
|
|
|
func (t Transform) ScaledToY(y Float) Transform {
|
|
|
|
t.S.Y = y
|
|
|
|
return t
|
|
|
|
}
|
|
|
|
|
2023-02-17 23:51:40 +03:00
|
|
|
// Returns the GeoM with corresponding
|
2023-05-30 22:35:49 +03:00
|
|
|
// 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-06-03 10:39:15 +03:00
|
|
|
g.Translate(-t.RA.X * t.S.X, -t.RA.Y * t.S.Y)
|
2023-02-17 23:51:40 +03:00
|
|
|
g.Rotate(t.R)
|
2023-05-30 22:35:49 +03:00
|
|
|
g.Translate(t.P.X, t.P.Y)
|
2023-02-17 23:51:40 +03:00
|
|
|
|
|
|
|
return *g
|
|
|
|
}
|
|
|
|
|