summaryrefslogtreecommitdiff
path: root/sly/transform.scm
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-08-03 20:33:01 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-08-25 19:33:07 -0400
commit1963e911026046f528a2923a924a39b55947558e (patch)
treee54f9e5b4b0b506a9ab1a053eca24f2da6989b15 /sly/transform.scm
parent0c5b039acbcc479f7930864811a59c012ab12e2d (diff)
Fix transform* procedure.
* sly/transform.scm (transform*): Perform matrix multiplication correctly.
Diffstat (limited to 'sly/transform.scm')
-rw-r--r--sly/transform.scm27
1 files changed, 10 insertions, 17 deletions
diff --git a/sly/transform.scm b/sly/transform.scm
index 05ce32d..ece4b06 100644
--- a/sly/transform.scm
+++ b/sly/transform.scm
@@ -114,26 +114,19 @@ null-transform if called without any arguments."
(define (transform* . transforms)
"Return the product of all given transformation matrices. Return
identity-transform if called without any arguments."
- (cond
- ((null? transforms)
- identity-transform)
- ((null? (cdr transforms))
- (car transforms))
- (else
- (let ((result (make-4x4-matrix)))
- (array-copy! (transform-matrix (car transforms)) result)
- (for-each
- (lambda (t)
- (let ((m (transform-matrix t)))
- (do-ec
+ (define (mul a b)
+ (let ((m1 (transform-matrix a))
+ (m2 (transform-matrix b))
+ (m3 (make-4x4-matrix)))
+ (do-ec
(: r 4) (: c 4)
(let ((x (sum-ec
(: k 4)
- (* (array-ref m r k)
- (array-ref result k c)))))
- (array-set! result x r c)))))
- (cdr transforms))
- (%make-transform result)))))
+ (* (array-ref m1 r k)
+ (array-ref m2 k c)))))
+ (array-set! m3 x r c)))
+ (%make-transform m3)))
+ (reduce mul identity-transform transforms))
(define (translate v)
"Return a new transform that translates by the 2D or 3D vector V."