summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2017-01-13 19:57:22 -0500
committerDavid Thompson <dthompson2@worcester.edu>2017-01-13 19:57:22 -0500
commit14ab9fb71e58ade255cd13eedd35d0ab758d044f (patch)
tree22fe8c9ca3d65ce1686548be1420f5710eb1dd73
parent027671d62f3453eca3fde5fb46d5270a075121d7 (diff)
math: matrix: Use vectors for matrix ops.
-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)))))