summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2022-07-31 12:39:11 -0400
committerDavid Thompson <dthompson2@worcester.edu>2022-07-31 12:39:11 -0400
commit06f4940a757c478b8474808961fae41c983c88d7 (patch)
tree3860750d28a853a13aa14a09a3a45b842761a00c
parent4dea11e31a0ec1b14b67625d4506007cd0542759 (diff)
node-2d: Reimplement refresh-matrics to avoid use of is-a?
-rw-r--r--starling/node-2d.scm36
1 files changed, 21 insertions, 15 deletions
diff --git a/starling/node-2d.scm b/starling/node-2d.scm
index f6fc190..005d7f1 100644
--- a/starling/node-2d.scm
+++ b/starling/node-2d.scm
@@ -369,22 +369,28 @@
(set! (dirty-matrix? node) #t)
(set! (dirty-bounding-box? node) #t))
+(define-method (refresh-local-matrix (node <node-2d>))
+ (matrix4-2d-transform! (local-matrix node)
+ #:origin (origin node)
+ #:position (render-position node)
+ #:rotation (rotation node)
+ #:scale (scale node)
+ #:skew (skew node)))
+
+(define-method (refresh-world-matrix (node <node-2d>) (parent <node-2d>))
+ (matrix4-mult! (world-matrix node) (local-matrix node) (world-matrix parent)))
+
+;; If a node has no parent or the parent is a 2D node, we simply copy
+;; the local matrix as the world matrix.
+(define-method (refresh-world-matrix (node <node-2d>) parent)
+ (let ((world (world-matrix node)))
+ (matrix4-identity! world)
+ (matrix4-mult! world world (local-matrix node))))
+
(define-method (refresh-matrices (node <node-2d>))
- (let ((local (local-matrix node))
- (world (world-matrix node)))
- (matrix4-2d-transform! local
- #:origin (origin node)
- #:position (render-position node)
- #:rotation (rotation node)
- #:scale (scale node)
- #:skew (skew node))
- ;; Compute world matrix by multiplying by the parent node's
- ;; matrix, if there is a 2D parent node, that is.
- (if (and (parent node) (is-a? (parent node) <node-2d>))
- (matrix4-mult! world local (world-matrix (parent node)))
- (begin
- (matrix4-identity! world)
- (matrix4-mult! world world local)))))
+ (refresh-local-matrix node)
+ (refresh-world-matrix node (parent node)))
+
(define-method (on-child-resize (node <node-2d>) child)
#t)