From 81170b37a41ab347c6a5f74d2d648cd0b2173c9d Mon Sep 17 00:00:00 2001 From: David Thompson Date: Wed, 16 Dec 2020 08:48:23 -0500 Subject: node-2d: Reduce matrix multiplication when camera is tracking a target. --- starling/node-2d.scm | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/starling/node-2d.scm b/starling/node-2d.scm index 6fd80ba..095c5ca 100644 --- a/starling/node-2d.scm +++ b/starling/node-2d.scm @@ -155,19 +155,19 @@ ;; This method can be overridden by subclasses to create custom camera ;; movement. (define-method (follow-target (camera )) - (let ((p (position camera))) - (set-vec2! p 0.0 0.0) - (transform! (world-matrix (target camera)) p) + (let ((p (position camera)) + (m (view-matrix camera)) + (w (world-matrix (target camera)))) + (set-vec2! p (matrix4-x w) (matrix4-y w)) (vec2-mult! p -1.0) - (vec2-add! p (offset camera)))) + (vec2-add! p (offset camera)) + (matrix4-translate! m (position camera)) + (matrix4-mult! m m (projection-matrix camera)))) (define-syntax-rule (with-camera camera body ...) (begin (when (target camera) - (follow-target camera) - (let ((m (view-matrix camera))) - (matrix4-translate! m (position camera)) - (matrix4-mult! m m (projection-matrix camera)))) + (follow-target camera)) (with-viewport (viewport camera) (with-projection (if (target camera) (view-matrix camera) -- cgit v1.2.3