diff --git a/transform.go b/transform.go index a88c09c..5e96fab 100644 --- a/transform.go +++ b/transform.go @@ -15,15 +15,15 @@ import "github.com/go-gl/mathgl/mgl32" // // pixel.Position(pixel.V(100, 100)).Rotate(math.Pi / 3).Scale(1.5) type Transform struct { - pos, anc Vec - sca, rot float64 + pos, anc, sca Vec + rot float64 } // Position creates a Transformation object with specified position. Anchor is (0, 0), rotation is 0 and scale is 1. func Position(position Vec) Transform { return Transform{ pos: position, - sca: 1, + sca: V(1, 1), } } @@ -50,6 +50,15 @@ func (t Transform) MoveAnchor(delta Vec) Transform { // Note, that subsequent calls to this method accumulate the final scale factor. Scaling two times by 2 is equivalent // to scaling once by 4. func (t Transform) Scale(scale float64) Transform { + t.sca *= V(scale, scale) + return t +} + +// ScaleXY scales the transform by the supplied X and Y factor. Note, that scale is applied before rotation. +// +// Note, that subsequent calls to this method accumulate the final scale factor. Scaling two times by 2 is equivalent +// to scaling once by 4. +func (t Transform) ScaleXY(scale Vec) Transform { t.sca *= scale return t } @@ -67,8 +76,8 @@ func (t Transform) Rotate(angle float64) Transform { func (t Transform) Mat3() mgl32.Mat3 { mat := mgl32.Ident3() mat = mat.Mul3(mgl32.Translate2D(float32(t.pos.X()), float32(t.pos.Y()))) - mat = mat.Mul3(mgl32.Scale2D(float32(t.sca), float32(t.sca))) mat = mat.Mul3(mgl32.Rotate3DZ(float32(t.rot))) + mat = mat.Mul3(mgl32.Scale2D(float32(t.sca.X()), float32(t.sca.Y()))) mat = mat.Mul3(mgl32.Translate2D(float32(t.anc.X()), float32(t.anc.Y()))) return mat }