diff options
-rw-r--r-- | chickadee/math/matrix.scm | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/chickadee/math/matrix.scm b/chickadee/math/matrix.scm index 00f5849..3e73f0c 100644 --- a/chickadee/math/matrix.scm +++ b/chickadee/math/matrix.scm @@ -45,6 +45,8 @@ matrix4-rotate-z! matrix4-rotate-z matrix4-2d-transform! + transform-x + transform-y transform!)) ;; 4x4 matrix @@ -419,13 +421,20 @@ happens with respect to ORIGIN, a 2D vector." (f32vector-set! bv 12 (- x (* ox q) (* oy s))) (f32vector-set! bv 13 (- y (* ox r) (* oy t))))))) +(define-inlinable (transform-x matrix x y) + (let ((bv (matrix4-bv matrix))) + (+ (* x (matrix-ref bv 0 0)) + (* y (matrix-ref bv 1 0)) + (matrix-ref bv 3 0)))) + +(define-inlinable (transform-y matrix x y) + (let ((bv (matrix4-bv matrix))) + (+ (* x (matrix-ref bv 0 1)) + (* y (matrix-ref bv 1 1)) + (matrix-ref bv 3 1)))) + (define-inlinable (transform! matrix v) - (let ((bv (matrix4-bv matrix)) - (x (vec2-x v)) + (let ((x (vec2-x v)) (y (vec2-y v))) - (set-vec2-x! v (+ (* x (matrix-ref bv 0 0)) - (* y (matrix-ref bv 1 0)) - (matrix-ref bv 3 0))) - (set-vec2-y! v (+ (* x (matrix-ref bv 0 1)) - (* y (matrix-ref bv 1 1)) - (matrix-ref bv 3 1))))) + (set-vec2-x! v (transform-x matrix x y)) + (set-vec2-y! v (transform-y matrix x y)))) |