aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/affine.lisp
diff options
context:
space:
mode:
authorColin Okay <colin@cicadas.surf>2022-07-06 09:33:14 -0500
committerColin Okay <colin@cicadas.surf>2022-07-06 09:33:14 -0500
commitfda1d9d08349dfe103b7af3ef8f305c1701933f6 (patch)
tree5cb896cf87d140df5bd05cb1f56566cfb0f17407 /src/core/affine.lisp
parent8c94460d8c8f8b44ca9bcdebbf2906e84c969b19 (diff)
[refactor] containers have render bounds
Diffstat (limited to 'src/core/affine.lisp')
-rw-r--r--src/core/affine.lisp26
1 files changed, 22 insertions, 4 deletions
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))))))))
+