summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sly/math.scm5
-rw-r--r--sly/transform.scm25
2 files changed, 10 insertions, 20 deletions
diff --git a/sly/math.scm b/sly/math.scm
index 1a5f2c6..8dc5cbf 100644
--- a/sly/math.scm
+++ b/sly/math.scm
@@ -30,6 +30,7 @@
cos-degrees
tan-degrees
atan-degrees
+ cotan
clamp
linear-scale))
@@ -85,6 +86,10 @@
"Compute the arctangent in degrees of the coordinates Y and X."
(radians->degrees (atan y x)))
+(define (cotan z)
+ "Return the cotangent of Z."
+ (/ 1 (tan z)))
+
(define (clamp min max x)
"Restrict X to the range defined by MIN and MAX. Assumes that MIN is
actually less than MAX."
diff --git a/sly/transform.scm b/sly/transform.scm
index ece4b06..f8bba23 100644
--- a/sly/transform.scm
+++ b/sly/transform.scm
@@ -213,23 +213,8 @@ FAR."
"Return a new transform 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 ((size (* near (tan (/ (degrees->radians field-of-vision) 2)))))
- (let ((left (- size))
- (right size)
- (top (/ size aspect-ratio))
- (bottom (/ (- size) aspect-ratio)))
- (make-transform (/ (* 2 near) (- right left)) ;; First row
- 0
- (/ (+ right left) (- right left))
- 0
- ;; Second row
- 0
- (/ (* 2 near) (- top bottom))
- (/ (+ top bottom) (- top bottom))
- 0
- ;; Third row
- 0 0
- (- (/ (+ far near) (- far near)))
- (- (/ (* 2 far near) (- far near)))
- ;; Fourth row
- 0 0 -1 0))))
+ (let ((f (cotan (/ (degrees->radians field-of-vision) 2))))
+ (make-transform (/ 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)))