summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)))