ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
Revision: 1.26
Committed: Wed Oct 6 15:20:11 2004 UTC (19 years, 8 months ago) by root
Content type: text/plain
Branch: MAIN
Changes since 1.25: +3 -0 lines
Log Message:
fixed missing header

File Contents

# User Rev Content
1 root 1.1 #include <cmath>
2    
3 root 1.26 #include <GL/gl.h>
4     #include <GL/glext.h>
5    
6 root 1.1 #include "oct.h"
7     #include "view.h"
8    
9 root 1.17 view::view ()
10 root 1.18 : gamma(1.0)
11 root 1.1 {
12     }
13    
14 root 1.17 view::~view ()
15 root 1.1 {
16     }
17    
18 root 1.17 bool view::may_draw (entity_base *e)
19 root 1.1 {
20     if (drawn.find (e) != drawn.end ())
21     return false;
22    
23     drawn.insert (e);
24     return true;
25     }
26    
27 root 1.18 void view::reset_projection ()
28 root 1.1 {
29 root 1.5 renormalize (orig, p);
30 root 1.3
31 root 1.1 glViewport (0, 0, w, h);
32    
33     glMatrixMode (GL_PROJECTION);
34     glLoadIdentity ();
35    
36     GLdouble aspect = (GLdouble)w/h;
37 root 1.6 GLdouble zNear = 0.1;
38     GLdouble zFar = 50.;
39 root 1.1
40     GLdouble ymax = zNear * tan (fov * (M_PI / 360.0));
41     glFrustum (-ymax * aspect, ymax * aspect, -ymax, ymax, zNear, zFar);
42    
43 root 1.6 d = normalize (d);//D
44     u = normalize (u);//D
45 root 1.1 vec3 rz = -d;
46     vec3 rx = cross (u, rz);
47     vec3 ry = cross (rz, rx);
48    
49 root 1.17 matrix &m = projection;
50 root 1.16 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
51     m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
52     m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
53 root 1.3 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
54    
55     glMultMatrixf ((GLfloat *)m.data);
56 root 1.6
57 root 1.5 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
58    
59 root 1.17 frustum.l = plane ( m(3,0) + m(0,0), m(3,1) + m(0,1), m(3,2) + m(0,2), m(3,3) + m(0,3) );
60     frustum.r = plane ( m(3,0) - m(0,0), m(3,1) - m(0,1), m(3,2) - m(0,2), m(3,3) - m(0,3) );
61     frustum.b = plane ( m(3,0) + m(1,0), m(3,1) + m(1,1), m(3,2) + m(1,2), m(3,3) + m(1,3) );
62     frustum.t = plane ( m(3,0) - m(1,0), m(3,1) - m(1,1), m(3,2) - m(1,2), m(3,3) - m(1,3) );
63     frustum.n = plane ( m(3,0) + m(2,0), m(3,1) + m(2,1), m(3,2) + m(2,2), m(3,3) + m(2,3) );
64     frustum.f = plane ( m(3,0) - m(2,0), m(3,1) - m(2,1), m(3,2) - m(2,2), m(3,3) - m(2,3) );
65 root 1.1
66 root 1.13 glMatrixMode (GL_MODELVIEW);
67 root 1.12 glLoadIdentity ();
68 root 1.16 glTranslatef (-p.x, -p.y, -p.z);
69 root 1.18 }
70    
71     void view::begin ()
72     {
73     vismap.clear ();
74 root 1.19 vislist.clear ();
75 root 1.18
76     generation++;
77 root 1.12
78 root 1.18 reset_projection ();
79    
80     // check occlusion queries here
81 root 1.24 #if 0
82 root 1.20 for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i)
83 root 1.22 //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query));
84     occ_query_result ((*i)->occ_query);
85 root 1.20
86 root 1.17 checklist.clear ();
87 root 1.24 #endif
88 root 1.18
89 root 1.17 world.detect_visibility (*this);
90 root 1.18 }
91    
92     void view::end ()
93     {
94     vismap.clear ();
95     }
96    
97     void view::pass (enum mode m)
98     {
99     mode = m;
100    
101     glDisable (GL_ALPHA_TEST);
102     glDisable (GL_BLEND);
103 root 1.4
104 root 1.18 if (mode == view::DEPTH)
105     {
106     glEnable (GL_POLYGON_OFFSET_FILL);
107     glPolygonOffset (0, 1);
108     glDepthFunc (GL_LESS);
109     glDisable (GL_LIGHTING);
110     glColorMask (0, 0, 0, 0);
111 root 1.24 cgGLEnableProfile (vsh_profile);// z-fighting??
112 root 1.23 cgGLDisableProfile (fsh_profile);
113 root 1.18 }
114     else
115     {
116     glEnable (GL_MINMAX);
117     glDisable (GL_POLYGON_OFFSET_FILL);
118     glDepthFunc (GL_LESS);
119     glDepthMask (0);
120 root 1.23 cgGLEnableProfile (vsh_profile);
121     cgGLEnableProfile (fsh_profile);
122 root 1.18 }
123    
124 root 1.17 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i)
125     (*i)->display (*this);
126    
127     drawn.clear ();
128 root 1.24
129 root 1.25 if (mode == view::DEPTH)
130     {
131     static int count; count++;
132     if (farlist.size ())
133     printf ("%d: size %d\n", count, farlist.size ());
134    
135     glDepthFunc (GL_LEQUAL);
136     for (vector<octant *>::iterator i = farlist.begin (); i != farlist.end (); ++i)
137     (*i)->draw_bbox (*this);
138    
139     farlist.clear ();
140     }
141 root 1.4
142     glColorMask (1, 1, 1, 0);
143     glDepthMask (1);
144 root 1.1 }
145 root 1.6
146 root 1.1