summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2022-08-01 16:03:25 -0400
committerDavid Thompson <dthompson2@worcester.edu>2022-08-01 16:06:44 -0400
commit7e9c865bc248a996ba9a360eb1392d05aa8a2010 (patch)
treedc85e71dc1837694b2a64cb9fa715258e74bfc1e
parent8da5b88f09b12dd5fbecdcc65d6e02888ace31f9 (diff)
math: matrix: Clean up matrix4-2d-transform! implementation.
-rw-r--r--chickadee/math/matrix.scm72
1 files changed, 35 insertions, 37 deletions
diff --git a/chickadee/math/matrix.scm b/chickadee/math/matrix.scm
index db05dd6..095699c 100644
--- a/chickadee/math/matrix.scm
+++ b/chickadee/math/matrix.scm
@@ -751,46 +751,44 @@ position EYE, with the top of the viewport facing UP."
(matrix4-rotate-z! matrix angle)
matrix))
-(define matrix4-2d-transform!
- (let ((tmp (make-null-matrix4))
- (offset (vec2 0.0 0.0))
- (null-vec2 (vec2 0.0 0.0))
- (default-scale (vec2 1.0 1.0)))
- (lambda* (matrix
- #:key
- (origin null-vec2)
- (position null-vec2)
- (rotation 0.0)
- (scale default-scale)
- (shear null-vec2))
- "Store in MATRIX the transformation described by POSITION, a 2D
+(define %null-vec2 (vec2 0.0 0.0))
+(define %default-scale (vec2 1.0 1.0))
+
+(define* (matrix4-2d-transform! matrix
+ #:key
+ (origin %null-vec2)
+ (position %null-vec2)
+ (rotation 0.0)
+ (scale %default-scale)
+ (shear %null-vec2))
+ "Store in MATRIX the transformation described by POSITION, a 2D
vector or rect, ROTATION, a scalar representing a rotation about the Z
axis, SCALE, a 2D vector, and SHEAR, a 2D vector. The transformation
happens with respect to ORIGIN, a 2D vector."
- (let* ((bv (matrix4-bv matrix))
- (x (vec2-x position))
- (y (vec2-y position))
- (ox (vec2-x origin))
- (oy (vec2-y origin))
- (sx (vec2-x scale))
- (sy (vec2-y scale))
- (kx (vec2-x shear))
- (ky (vec2-y shear))
- (c (cos rotation))
- (s (sin rotation))
- (q (* c sx))
- (r (+ (* s sx) (* c sy ky)))
- (s (- (* c sx kx) (* s sy)))
- (t (* c sy)))
- (bytevector-fill! bv 0)
- (f32vector-set! bv 10 1.0)
- (f32vector-set! bv 15 1.0)
- (f32vector-set! bv 0 q)
- (f32vector-set! bv 1 r)
- (f32vector-set! bv 4 s)
- (f32vector-set! bv 5 t)
- (f32vector-set! bv 12 (- x (* ox q) (* oy s)))
- (f32vector-set! bv 13 (- y (* ox r) (* oy t)))))))
+ (let* ((bv (matrix4-bv matrix))
+ (x (vec2-x position))
+ (y (vec2-y position))
+ (ox (vec2-x origin))
+ (oy (vec2-y origin))
+ (sx (vec2-x scale))
+ (sy (vec2-y scale))
+ (kx (vec2-x shear))
+ (ky (vec2-y shear))
+ (c (cos rotation))
+ (s (sin rotation))
+ (q (* c sx))
+ (r (+ (* s sx) (* c sy ky)))
+ (s (- (* c sx kx) (* s sy)))
+ (t (* c sy)))
+ (bytevector-fill! bv 0)
+ (f32vector-set! bv 0 q)
+ (f32vector-set! bv 1 r)
+ (f32vector-set! bv 4 s)
+ (f32vector-set! bv 5 t)
+ (f32vector-set! bv 10 1.0)
+ (f32vector-set! bv 12 (- x (* ox q) (* oy s)))
+ (f32vector-set! bv 13 (- y (* ox r) (* oy t)))
+ (f32vector-set! bv 15 1.0)))
(define-inlinable (matrix4-transform-x matrix x y)
(let ((bv (matrix4-bv matrix)))