diff options
-rw-r--r-- | chickadee/math/matrix.scm | 12 |
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 |