ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/libgender/view.C
(Generate patch)

Comparing libgender/view.C (file contents):
Revision 1.11 by root, Tue Oct 5 06:03:16 2004 UTC vs.
Revision 1.23 by root, Wed Oct 6 05:24:03 2004 UTC

1#include <cmath> 1#include <cmath>
2 2
3#include "oct.h" 3#include "oct.h"
4#include "view.h" 4#include "view.h"
5 5
6draw_context::draw_context (view &v) 6view::view ()
7: v(v), l(0), mode(LIGHTED) 7: gamma(1.0)
8{ 8{
9} 9}
10 10
11draw_context::~draw_context () 11view::~view ()
12{ 12{
13} 13}
14 14
15void draw_context::transform (const matrix &m)
16{
17 modelview = modelview * m;
18 matrix d = projection * modelview;
19
20 glLoadMatrixf ((GLfloat *)&d);
21
22#if 0
23 for (int i = 0; i < 4; i++)
24 for (int j = 0; j < 4 ; j++)
25 mvp[i](j) = d(i,j);
26#endif
27}
28
29bool draw_context::may_draw (entity_base *e) 15bool view::may_draw (entity_base *e)
30{ 16{
31 if (drawn.find (e) != drawn.end ()) 17 if (drawn.find (e) != drawn.end ())
32 return false; 18 return false;
33 19
34 drawn.insert (e); 20 drawn.insert (e);
35 return true; 21 return true;
36} 22}
37 23
38void view::draw (draw_context &ctx) 24void view::reset_projection ()
39{ 25{
40 // check occlusion queries here
41
42 ctx.generation++;
43
44 renormalize (orig, p); 26 renormalize (orig, p);
45 27
46 if (ctx.mode == draw_context::DEPTH)
47 {
48 glEnable (GL_POLYGON_OFFSET_FILL);
49 glPolygonOffset (0, 1);
50 glDepthFunc (GL_LESS);
51 glDisable (GL_LIGHTING);
52 glColorMask (0, 0, 0, 0);
53 }
54 else
55 {
56 glDisable (GL_POLYGON_OFFSET_FILL);
57 glDrawBuffer (GL_BACK);
58 glDepthFunc (GL_LEQUAL);
59 glEnable (GL_LIGHTING);
60 glDepthMask (0);
61 }
62
63 glViewport (0, 0, w, h); 28 glViewport (0, 0, w, h);
64 29
65 glMatrixMode (GL_PROJECTION); 30 glMatrixMode (GL_PROJECTION);
66 glLoadIdentity (); 31 glLoadIdentity ();
67 32
76 u = normalize (u);//D 41 u = normalize (u);//D
77 vec3 rz = -d; 42 vec3 rz = -d;
78 vec3 rx = cross (u, rz); 43 vec3 rx = cross (u, rz);
79 vec3 ry = cross (rz, rx); 44 vec3 ry = cross (rz, rx);
80 45
81 matrix &m = ctx.projection; 46 matrix &m = projection;
82 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = -p.x; 47 m(0,0) = rx.x; m(0,1) = rx.y; m(0,2) = rx.z; m(0,3) = 0;
83 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = -p.y; 48 m(1,0) = ry.x; m(1,1) = ry.y; m(1,2) = ry.z; m(1,3) = 0;
84 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = -p.z; 49 m(2,0) = rz.x; m(2,1) = rz.y; m(2,2) = rz.z; m(2,3) = 0;
85 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1; 50 m(3,0) = 0; m(3,1) = 0; m(3,2) = 0; m(3,3) = 1;
86 51
87 glMultMatrixf ((GLfloat *)m.data); 52 glMultMatrixf ((GLfloat *)m.data);
88 53
89 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m); 54 glGetFloatv (GL_PROJECTION_MATRIX, (GLfloat *)&m);
90 55
91 ctx.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) ); 56 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) );
92 ctx.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) ); 57 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) );
93 ctx.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) ); 58 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) );
94 ctx.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) ); 59 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) );
95 ctx.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) ); 60 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) );
96 ctx.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) ); 61 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) );
97 62
98 ctx.modelview.identity (); 63 glMatrixMode (GL_MODELVIEW);
64 glLoadIdentity ();
65 glTranslatef (-p.x, -p.y, -p.z);
66}
99 67
100 glMatrixMode (GL_PROJECTION);//D 68void view::begin ()
101 world.draw (ctx); 69{
70 vismap.clear ();
71 vislist.clear ();
102 72
73 generation++;
74
75 reset_projection ();
76
77 // check occlusion queries here
78 for (vector<octant *>::iterator i = checklist.begin (); i != checklist.end (); ++i)
79 //printf ("%p %d\n", *i, occ_query_result ((*i)->occ_query));
80 occ_query_result ((*i)->occ_query);
81
82 checklist.clear ();
83
84 world.detect_visibility (*this);
85}
86
87void view::end ()
88{
89 vismap.clear ();
90}
91
92void view::pass (enum mode m)
93{
94 mode = m;
95
96 glDisable (GL_ALPHA_TEST);
97 glDisable (GL_BLEND);
98
99 if (mode == view::DEPTH)
100 {
101 glEnable (GL_POLYGON_OFFSET_FILL);
102 glPolygonOffset (0, 1);
103 glDepthFunc (GL_LESS);
104 glDisable (GL_LIGHTING);
105 glColorMask (0, 0, 0, 0);
106 //cgGLDisableProfile (vsh_profile);
107 cgGLDisableProfile (fsh_profile);
108 }
109 else
110 {
111#if 0
112 glEnable (GL_MINMAX);
113#endif
114 glDisable (GL_POLYGON_OFFSET_FILL);
115 glDepthFunc (GL_LESS);
116 glDepthMask (0);
117 cgGLEnableProfile (vsh_profile);
118 cgGLEnableProfile (fsh_profile);
119 }
120
121 for (vector<octant *>::iterator i = vislist.begin (); i != vislist.end (); ++i)
122 (*i)->display (*this);
123
103 ctx.drawn.clear (); 124 drawn.clear ();
104 125
105 glColorMask (1, 1, 1, 0); 126 glColorMask (1, 1, 1, 0);
106 glDepthMask (1); 127 glDepthMask (1);
107} 128}
108 129

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines