From 06f4940a757c478b8474808961fae41c983c88d7 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Sun, 31 Jul 2022 12:39:11 -0400 Subject: node-2d: Reimplement refresh-matrics to avoid use of is-a? --- starling/node-2d.scm | 36 +++++++++++++++++++++--------------- 1 file 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 )) + (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 ) (parent )) + (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 ) parent) + (let ((world (world-matrix node))) + (matrix4-identity! world) + (matrix4-mult! world world (local-matrix node)))) + (define-method (refresh-matrices (node )) - (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) )) - (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 ) child) #t) -- cgit v1.2.3