rename Mat3->Mat, InvMat3->InvMat in Transform

This commit is contained in:
faiface 2016-12-21 20:32:52 +01:00
parent 45c2dd9be7
commit 074d1cedaa
2 changed files with 9 additions and 9 deletions

View File

@ -136,9 +136,9 @@ func (s *Shape) VertexArray() *pixelgl.VertexArray {
func (s *Shape) Draw(t ...Transform) {
mat := mgl32.Ident3()
for i := range t {
mat = mat.Mul3(t[i].Mat3())
mat = mat.Mul3(t[i].Mat())
}
mat = mat.Mul3(s.transform.Mat3())
mat = mat.Mul3(s.transform.Mat())
s.parent.Do(func(ctx pixelgl.Context) {
r, g, b, a := colorToRGBA(s.color)
@ -197,7 +197,7 @@ func NewMultiShape(parent pixelgl.Doer, shapes ...*Shape) *MultiShape {
for vertex := range shapeVertices {
if pos, ok := shapeVertices[vertex][positionVec2]; ok {
pos := pos.(mgl32.Vec2)
pos = shape.Transform().Mat3().Mul3x1(mgl32.Vec3{pos.X(), pos.Y(), 1}).Vec2()
pos = shape.Transform().Mat().Mul3x1(mgl32.Vec3{pos.X(), pos.Y(), 1}).Vec2()
shapeVertices[vertex][positionVec2] = pos
}
if color, ok := shapeVertices[vertex][colorVec4]; ok {

View File

@ -100,7 +100,7 @@ func (t Transform) Rotate(angle float64) Transform {
// Project transforms a vector by a transform.
func (t Transform) Project(v Vec) Vec {
mat := t.Mat3()
mat := t.Mat()
vec := mgl32.Vec3{float32(v.X()), float32(v.Y()), 1}
pro := mat.Mul3x1(vec)
return V(float64(pro.X()), float64(pro.Y()))
@ -108,14 +108,14 @@ func (t Transform) Project(v Vec) Vec {
// Unproject does the inverse operation to Project.
func (t Transform) Unproject(v Vec) Vec {
mat := t.InvMat3()
mat := t.InvMat()
vec := mgl32.Vec3{float32(v.X()), float32(v.Y()), 1}
unp := mat.Mul3x1(vec)
return V(float64(unp.X()), float64(unp.Y()))
}
// Mat3 returns a transformation matrix that satisfies previously set transform properties.
func (t Transform) Mat3() mgl32.Mat3 {
// Mat returns a transformation matrix that satisfies previously set transform properties.
func (t Transform) Mat() mgl32.Mat3 {
mat := mgl32.Ident3()
mat = mat.Mul3(mgl32.Translate2D(float32(t.pos.X()), float32(t.pos.Y())))
mat = mat.Mul3(mgl32.Rotate3DZ(float32(t.rot)))
@ -124,8 +124,8 @@ func (t Transform) Mat3() mgl32.Mat3 {
return mat
}
// InvMat3 returns an inverse transformation matrix to the matrix returned by Mat3 method.
func (t Transform) InvMat3() mgl32.Mat3 {
// InvMat returns an inverse transformation matrix to the matrix returned by Mat3 method.
func (t Transform) InvMat() mgl32.Mat3 {
mat := mgl32.Ident3()
mat = mat.Mul3(mgl32.Translate2D(float32(t.anc.X()), float32(t.anc.Y())))
mat = mat.Mul3(mgl32.Scale2D(float32(1/t.sca.X()), float32(1/t.sca.Y())))