source: project/gl-display-glx/gl-proj.scm @ 3547

Last change on this file since 3547 was 3547, checked in by thu, 14 years ago

commit before removal of non gl-display files

File size: 1.8 KB
RevLine 
[3309]1;;; gl-proj.scm
2;;; 2007-03-03 -- thu
3;;;
4;;; The intent of this file is to provide camera/projection
5;;; related procedures : orthographic, FPS camera, ...
6
7(define M_PI 3.14159265358979323846) ; from math.h
8
9(define (orthographic left right bottom top near far)
10  (gl:Ortho left right bottom top near far))
11
12;(define *xmin* 0)
13;(define *xmax* 0)
14;(define *ymin* 0)
15;(define *ymax* 0)
16(define (perspective fovy aspect znear zfar)
17  (let* ((ymax (* znear (tan (/ (* fovy M_PI) 360.0))))
18         (ymin (- ymax))
19         (xmax (* ymax aspect))
20         (xmin (- xmax)))
21;    (set! *xmin* xmin)
22;    (set! *xmax* xmax)
23;    (set! *ymin* ymin)
24;    (set! *ymax* ymax)
25    (gl:Frustum xmin xmax ymin ymax znear zfar)))
26
27(define (gl-proj:viewport window)
28  (let ((w (gl-display:width window))
29        (h (gl-display:height window)))
30    (gl:Viewport 0 0 w h)))
31
32(define (gl-proj:perspective window)
33  (let ((w (gl-display:width window))
34        (h (gl-display:height window)))
35    (gl:MatrixMode gl:PROJECTION)
36    (gl:LoadIdentity)
37    (perspective 45 (/ w (if (eq? 0 h) 1 h)) 1 1024)
38    (gl:MatrixMode gl:MODELVIEW)
39    (gl:LoadIdentity)))
40
41(define (gl-proj:orthographic window)
42  (let ((w (gl-display:width window))
43        (h (gl-display:height window)))
44    (gl:MatrixMode gl:PROJECTION)
45    (gl:LoadIdentity)
46  ; Q: is it normal that I have to use height-1 and -1, and not height and 0 ?
47  ; Maybe 0.375 as in blender ? I think there's a discussion about this in the red book
[3547]48;    (gl:Ortho 0 w (- h 1) -1 -4 4) ; y goes up
49    (gl:Ortho 0 w 0 h -4 4)         ; y goes down
50;    (gl:Ortho (- (/ w 2)) (/ w 2) (- (/ h 2)) (/ h 2) -4 4) ; 0/0 at center
[3309]51;    (gl:Ortho *xmin* *xmax* *ymin* *ymax* -1 1)
52    (gl:MatrixMode gl:MODELVIEW)
53    (gl:LoadIdentity)))
54
55
56(define-macro (preserving-matrices . rest)
57  `(begin (gl:PushMatrix)
58          ,@rest
59          (gl:PopMatrix)))
[3343]60
Note: See TracBrowser for help on using the repository browser.