summaryrefslogtreecommitdiff
path: root/catbird/node-2d.scm
diff options
context:
space:
mode:
Diffstat (limited to 'catbird/node-2d.scm')
-rw-r--r--catbird/node-2d.scm22
1 files changed, 13 insertions, 9 deletions
diff --git a/catbird/node-2d.scm b/catbird/node-2d.scm
index 868604a..79a0dba 100644
--- a/catbird/node-2d.scm
+++ b/catbird/node-2d.scm
@@ -102,6 +102,7 @@
teleport
world-bounding-box
world-matrix
+ world->local
<sprite>
texture
@@ -602,19 +603,22 @@
(define-method (follow-bezier-path (node <node-2d>) path duration)
(follow-bezier-path node path duration #t))
+(define-method (world->local (node <node-2d>) p)
+ (matrix4-transform-vec2 (inverse-world-matrix node) p))
+
(define-method (pick (node <node-2d>) p)
(let loop ((kids (reverse (children node))))
(match kids
(()
- (let* ((m (inverse-world-matrix node))
- (x (vec2-x p))
- (y (vec2-y p))
- (tx (matrix4-transform-x m x y))
- (ty (matrix4-transform-y m x y)))
- (and (>= tx 0.0)
- (< tx (width node))
- (>= ty 0.0)
- (< ty (height node))
+ ;; Multiply the cursor position by the inverse world matrix to
+ ;; translate world coordinates into node-local coordinates.
+ (let* ((p* (world->local node p))
+ (x (vec2-x p*))
+ (y (vec2-y p*)))
+ (and (>= x 0.0)
+ (< x (width node))
+ (>= y 0.0)
+ (< y (height node))
node)))
((child . rest)
(let ((o (origin node)))