summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--chickadee/math/matrix.scm34
1 files changed, 18 insertions, 16 deletions
diff --git a/chickadee/math/matrix.scm b/chickadee/math/matrix.scm
index 5c5fdaa..26b70fe 100644
--- a/chickadee/math/matrix.scm
+++ b/chickadee/math/matrix.scm
@@ -37,7 +37,7 @@
matrix4-scale
matrix4-rotate-z!
matrix4-rotate-z
- transform))
+ transform!))
;; 4x4 matrix
(define-record-type <matrix4>
@@ -258,16 +258,16 @@ FAR."
(- (/ (+ far near) (- far near)))
1.0))
-(define (matrix4-translate! matrix x y)
+(define (matrix4-translate! matrix v)
(init-matrix4 matrix
- 1.0 0.0 0.0 0.0
- 0.0 1.0 0.0 0.0
- 0.0 0.0 1.0 0.0
- x y 0.0 1.0))
+ 1.0 0.0 0.0 0.0
+ 0.0 1.0 0.0 0.0
+ 0.0 0.0 1.0 0.0
+ (vec2-x v) (vec2-y v) 0.0 1.0))
-(define (matrix4-translate x y)
+(define (matrix4-translate v)
(let ((matrix (make-null-matrix4)))
- (matrix4-translate! matrix x y)
+ (matrix4-translate! matrix v)
matrix))
(define (matrix4-scale! matrix s)
@@ -295,11 +295,13 @@ FAR."
(matrix4-rotate-z! matrix angle)
matrix))
-(define (transform matrix x y)
- (let ((bv (matrix4-bv matrix)))
- (values (+ (* x (matrix-ref bv 0 0))
- (* y (matrix-ref bv 1 0))
- (matrix-ref bv 3 0))
- (+ (* 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))
+ (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)))))