summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Thompson <dthompson2@worcester.edu>2014-08-03 20:34:33 -0400
committerDavid Thompson <dthompson2@worcester.edu>2014-08-25 19:33:07 -0400
commite8f5b8cca92c41cd4a9a62c297ec01a38c786063 (patch)
treea975592f1397965a4bcb6ab6ff14aba200704db5
parent1963e911026046f528a2923a924a39b55947558e (diff)
Simplify perspective-projection implementation.
* sly/math.scm (cotan): New procedure. * sly/transform.scm (perspective-projection): Simplify.
-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)))