diff options
author | David Thompson <dthompson@vistahigherlearning.com> | 2020-12-16 08:48:23 -0500 |
---|---|---|
committer | David Thompson <dthompson@vistahigherlearning.com> | 2020-12-16 08:48:23 -0500 |
commit | 81170b37a41ab347c6a5f74d2d648cd0b2173c9d (patch) | |
tree | ce2366712484100c65b287692ab5191919659cc5 | |
parent | 1f33135b58fc12f0e4f7e661e0c5a64498e17815 (diff) |
node-2d: Reduce matrix multiplication when camera is tracking a target.
-rw-r--r-- | starling/node-2d.scm | 16 |
1 files 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 <camera-2d>)) - (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) |