summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2019-01-06 22:47:46 -0500
committerDavid Thompson <dthompson2@worcester.edu>2019-01-06 22:47:46 -0500
commitc93716843828ccff80831294008a8456d9cadc4f (patch)
treed4e3aa829d7627cf4cd0416c17620b00f639b1c4
parent4607a0bc3021a0d12ed792de91857d5fd86e1833 (diff)
math: matrix: Add transform-x and transform-y procedures.
* chickadee/math/matrix.scm (transform-x, transform-y): New procedures.
-rw-r--r--chickadee/math/matrix.scm25
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))))