From fda1d9d08349dfe103b7af3ef8f305c1701933f6 Mon Sep 17 00:00:00 2001 From: Colin Okay Date: Wed, 6 Jul 2022 09:33:14 -0500 Subject: [refactor] containers have render bounds --- src/core/affine.lisp | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) (limited to 'src/core/affine.lisp') diff --git a/src/core/affine.lisp b/src/core/affine.lisp index 7c87d16..7cfb805 100644 --- a/src/core/affine.lisp +++ b/src/core/affine.lisp @@ -3,7 +3,7 @@ (in-package #:wheelwork) (defclass/std affine (unit) - ((cached-model cached-projected-matrix cached-application :a) + ((cached-model cached-projected-matrix cached-application cached-rectangle :a) (base-width base-height :r :std 1.0 :doc "Determined by content.") (scale-x scale-y :std 1.0) (rotation x y :std 0.0))) @@ -13,9 +13,8 @@ (case (closer-mop:slot-definition-name slot) ((x y scale-x scale-y rotation) (setf (cached-model affine) nil - (cached-projected-matrix affine) nil)))) - - + (cached-projected-matrix affine) nil + (cached-rectangle affine) nil)))) (defun scale-by (affine amount) (with-accessors ((sx scale-x) (sy scale-y)) affine @@ -69,3 +68,22 @@ (setf (cached-projected-matrix affine) (mat:marr (mat:m* (application-projection (app-of-unit affine)) (model-matrix affine)))))) + +(defmethod get-rect ((affine-unit affine)) + (or (cached-rectangle affine-unit) + (setf (cached-rectangle affine-unit) + (with-accessors ((x x) (y y) (w width) (h height) (r rotation)) affine-unit + (let ((m + (mat:meye 4)) + (tr + (vec:vec (+ x (* 0.5 w)) (+ y (* 0.5 h)) 0.0))) + (mat:nmtranslate m tr) + (mat:nmrotate m vec:+vz+ r) + (mat:nmtranslate m (vec:v* -1.0 tr)) + + (list (mat:m* m (vec:vec x y 0.0 1.0)) + (mat:m* m (vec:vec x (+ y h) 0.0 1.0)) + (mat:m* m (vec:vec (+ x w) (+ y h) 0.0 1.0)) + (mat:m* m (vec:vec (+ x w) y 0.0 1.0)) + (mat:m* m (vec:vec x y 0.0 1.0)))))))) + -- cgit v1.2.3