summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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)