Permalink
Browse files

Make with-pushed-matrix accept varying numbers of matrices to avoid s…

…tacking.
  • Loading branch information...
Shinmera committed Jun 25, 2017
1 parent f0fe771 commit 0a9716b20210b617e0b8877443cbc23cc0966355
Showing with 18 additions and 14 deletions.
  1. +5 −5 controller.lisp
  2. +13 −9 transforms.lisp
View
@@ -74,14 +74,14 @@
(defmethod paint ((controller controller) target)
(when (show-overlay controller)
(with-pushed-matrix (*projection-matrix* :zero)
(with-pushed-matrix ((*projection-matrix* :zero)
(*model-matrix* :identity)
(*view-matrix* :identity))
(orthographic-projection 0 (width *context*)
0 (height *context*)
0 10)
(with-pushed-matrix (*model-matrix* :identity)
(translate-by 0 (height *context*) 0)
(with-pushed-matrix (*view-matrix* :identity)
(paint (text controller) target))))))
(translate-by 0 (height *context*) 0)
(paint (text controller) target))))
(define-handler (controller quit-game) (ev)
(quit *context*))
View
@@ -56,15 +56,19 @@
(defun orthographic-projection (left right bottom top near far)
(setf *projection-matrix* (mortho left right bottom top near far)))
(defmacro with-pushed-matrix ((&optional (accessor '(model-matrix)) fill) &body body)
(let ((variable (ecase (unlist accessor)
((*view-matrix* view-matrix) '*view-matrix*)
((*projection-matrix* projection-matrix) '*projection-matrix*)
((*model-matrix* model-matrix) '*model-matrix*))))
`(let ((,variable ,(ecase fill
(:zero `(mat4))
(:identity `(meye 4))
((:copy NIL) `(mcopy4 ,variable)))))
(defmacro with-pushed-matrix (specs &body body)
(let ((specs (or specs '(((model-matrix) :copy)))))
`(let ,(loop for spec in specs
for (accessor fill) = (enlist spec :copy)
for variable = (ecase (unlist accessor)
((*view-matrix* view-matrix) '*view-matrix*)
((*projection-matrix* projection-matrix) '*projection-matrix*)
((*model-matrix* model-matrix) '*model-matrix*))
collect `(,variable
,(ecase fill
(:zero `(mat4))
(:identity `(meye 4))
((:copy NIL) `(mcopy4 ,variable)))))
,@body)))
(defun translate (v &optional (matrix (model-matrix)))

0 comments on commit 0a9716b

Please sign in to comment.