diff --git a/src/maths/geometry.lisp b/src/maths/geometry.lisp index 4681940..b9ed6cb 100644 --- a/src/maths/geometry.lisp +++ b/src/maths/geometry.lisp @@ -54,14 +54,18 @@ mat))))) (defun calc-frustum-scale (fovy) - (/ 1.0 (tan (/ (maths:deg-to-rad fovy) 2.0)))) + (tan (/ (maths:deg-to-rad fovy) 2.0))) (defun make-persp-matrix (fovy aspect near far) - (let ((frustum-scale (calc-frustum-scale fovy))) - (f44:mat frustum-scale 0.0 0.0 0.0 - 0.0 (/ frustum-scale aspect) 0.0 0.0 - 0.0 0.0 (/ (+ far near) (- near far)) -1.0 - 0.0 0.0 (/ (* 2.0 far near) (- near far)) 0.0))) + (let ((range (calc-frustum-scale fovy))) + (let ((left (* (- range) aspect)) + (right (* range aspect)) + (bottom (- range)) + (top range)) + (f44:mat (/ (* near 2) (- right left)) 0.0 0.0 0.0 + 0.0 (/ (* near 2) (- top bottom)) 0.0 0.0 + 0.0 0.0 (/ (+ far near) (- near far)) -1.0 + 0.0 0.0 (/ (* 2.0 far near) (- near far)) 0.0)))) (defun make-ortho-matrix (width height) (f44:mat (/ 2.0 width) 0.0 0.0 -1.0