summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2017-08-13 13:55:21 -0400
committerDavid Thompson <dthompson2@worcester.edu>2017-09-13 21:16:30 -0400
commitf52d92b94148a0fd86ca4b44287543480dedb19f (patch)
tree4bf57230e71e9804f0abb2a492fdf58fd7d7e1a1
parent40a66f2e11d4a180554845312684299c2c2cbd43 (diff)
math: matrix: Add perspective-projection function.
* chickadee/math/matrix.scm (perspective-projection): New procedure.
-rw-r--r--chickadee/math/matrix.scm12
1 files changed, 12 insertions, 0 deletions
diff --git a/chickadee/math/matrix.scm b/chickadee/math/matrix.scm
index 2e94233..cb9f1e1 100644
--- a/chickadee/math/matrix.scm
+++ b/chickadee/math/matrix.scm
@@ -23,6 +23,7 @@
#:use-module (srfi srfi-9 gnu)
#:use-module (srfi srfi-4)
#:use-module (system foreign)
+ #:use-module (chickadee math)
#:use-module (chickadee math vector)
#:export (make-matrix4
make-null-matrix4
@@ -32,6 +33,7 @@
matrix4-identity!
make-identity-matrix4
orthographic-projection
+ perspective-projection
matrix4-translate!
matrix4-translate
matrix4-scale!
@@ -282,6 +284,16 @@ FAR."
(- (/ (+ far near) (- far near)))
1.0))
+(define (perspective-projection field-of-vision aspect-ratio near far)
+ "Return a new matrix4 that represents a perspective projection with
+a FIELD-OF-VISION in degrees, the desired ASPECT-RATIO, and the depth
+clipping plane NEAR and FAR."
+ (let ((f (cotan (/ field-of-vision 2))))
+ (make-matrix4 (/ f aspect-ratio) 0 0 0
+ 0 f 0 0
+ 0 0 (/ (+ far near) (- near far)) -1
+ 0 0 (/ (* 2 far near) (- near far)) 0)))
+
(define (matrix4-translate! matrix v)
(init-matrix4 matrix
1.0 0.0 0.0 0.0