2016-11-24 08:13:05 -06:00
|
|
|
package pixel
|
|
|
|
|
2017-01-12 04:44:54 -06:00
|
|
|
import "github.com/go-gl/mathgl/mgl32"
|
|
|
|
|
2016-12-23 13:25:47 -06:00
|
|
|
func clamp(x, low, high float64) float64 {
|
|
|
|
if x < low {
|
|
|
|
return low
|
|
|
|
}
|
|
|
|
if x > high {
|
|
|
|
return high
|
|
|
|
}
|
|
|
|
return x
|
2016-11-24 08:13:05 -06:00
|
|
|
}
|
2017-01-12 04:44:54 -06:00
|
|
|
|
2017-01-14 09:07:51 -06:00
|
|
|
func lerp(x float64, a, b Vec) Vec {
|
|
|
|
return a.Scaled(1-x) + b.Scaled(x)
|
|
|
|
}
|
|
|
|
|
|
|
|
func lerp2d(x, a, b Vec) Vec {
|
|
|
|
return V(
|
|
|
|
lerp(x.X(), a, b).X(),
|
|
|
|
lerp(x.Y(), a, b).Y(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2017-01-12 04:44:54 -06:00
|
|
|
func transformToMat(t ...Transform) mgl32.Mat3 {
|
|
|
|
mat := mgl32.Ident3()
|
|
|
|
for i := range t {
|
|
|
|
mat = mat.Mul3(t[i].Mat())
|
|
|
|
}
|
|
|
|
return mat
|
|
|
|
}
|
2017-01-14 09:07:51 -06:00
|
|
|
|
2017-02-22 13:57:22 -06:00
|
|
|
func pictureBounds(p *GLPicture, v Vec) Vec {
|
2017-01-14 09:07:51 -06:00
|
|
|
w, h := float64(p.Texture().Width()), float64(p.Texture().Height())
|
|
|
|
a := p.Bounds().Pos
|
|
|
|
b := p.Bounds().Pos + p.Bounds().Size
|
|
|
|
u := lerp2d(v, a, b)
|
|
|
|
return V(u.X()/w, u.Y()/h)
|
|
|
|
}
|