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

Comparing libgender/oct.C (file contents):
Revision 1.16 by root, Tue Oct 5 07:48:33 2004 UTC vs.
Revision 1.22 by root, Wed Oct 6 02:04:03 2004 UTC

21 { 21 {
22 id = *(occ_query_objects.end () - 1); 22 id = *(occ_query_objects.end () - 1);
23 occ_query_objects.pop_back (); 23 occ_query_objects.pop_back ();
24 } 24 }
25 else 25 else
26 glGenQueries (1, &id); 26 glGenQueriesARB (1, &id);
27 27
28 glBeginQuery (GL_SAMPLES_PASSED, id); 28 glBeginQueryARB (GL_SAMPLES_PASSED, id);
29 return id; 29 return id;
30} 30}
31 31
32#define end_occ_query() glEndQuery (GL_SAMPLES_PASSED); 32#define end_occ_query() glEndQueryARB (GL_SAMPLES_PASSED);
33 33
34static GLuint occ_query_result (GLuint id) 34static GLuint occ_query_result (GLuint id)
35{ 35{
36 GLuint count; 36 GLuint count;
37 37
38 glGetQueryObjectuiv (id, GL_QUERY_RESULT, &count); 38 glGetQueryObjectuivARB (id, GL_QUERY_RESULT, &count);
39 occ_query_objects.push_back (id); 39 occ_query_objects.push_back (id);
40 40
41 return count; 41 return count;
42} 42}
43 43
111 111
112void octant::remove (entity_base *e) 112void octant::remove (entity_base *e)
113{ 113{
114} 114}
115 115
116void octant::draw (draw_context &ctx) 116void octant::detect_visibility (view &ctx)
117{ 117{
118 visibility_state &vs = ctx.vismap[this]; 118 visibility_state &vs = ctx.vismap[this];
119 119
120 if (vs.generation != ctx.generation) 120 if (vs.generation != ctx.generation)
121 vs.visibility = visibility_state::UNKNOWN; 121 vs.visibility = visibility_state::UNKNOWN;
122 122
123 const sector &cam = ctx.v.orig; 123 const sector &cam = ctx.orig;
124#if 0
125 if (cam.x >= orig.x && cam.x <= orig.x + extent 124 if (cam.x >= orig.x && cam.x <= orig.x + extent
126 && cam.y >= orig.y && cam.y <= orig.y + extent 125 && cam.y >= orig.y && cam.y <= orig.y + extent
127 && cam.z >= orig.z && cam.z <= orig.z + extent) 126 && cam.z >= orig.z && cam.z <= orig.z + extent)
128 { 127 {
129 vs.visibility = visibility_state::PARTIAL; 128 vs.visibility = visibility_state::PARTIAL;
130 vs.generation = ctx.generation; 129 vs.generation = ctx.generation;
131 } 130 }
132 else 131 else
133#endif
134 { 132 {
135 //printf ("OCTANT %d,%d,%d+%d\n", orig.x, orig.y, orig.z, extent);
136 point center ( 133 point center (
137 orig.x + (soffs)extent / 2 - cam.x , 134 orig.x + (soffs)extent / 2 - cam.x,
138 orig.y + (soffs)extent / 2 - cam.y , 135 orig.y + (soffs)extent / 2 - cam.y,
139 orig.z + (soffs)extent / 2 - cam.z 136 orig.z + (soffs)extent / 2 - cam.z
140 ); 137 );
141 138
142 GLfloat dia = (0.5 * sqrtf (3))*(GLfloat)extent; 139 GLfloat dia = (0.5 * sqrtf (3))*(GLfloat)extent;
143 140
144#if 0
145 printf ("DISTANCE %f,%f,%f TO near: %f\n",
146 center.x, center.y, center.z,
147 ctx.frustum.n.distance (center)
148 );
149#endif
150#if 0
151 printf ("DISTANCE %f,%f,%f TO far: %f\n",
152 center.x, center.y, center.z,
153 ctx.frustum.f.distance (center)
154 );
155#endif
156#if 1
157 if (ctx.frustum.t.distance (center) < -dia) return; 141 if (ctx.frustum.t.distance (center) < -dia) return;
158 if (ctx.frustum.b.distance (center) < -dia) return; 142 if (ctx.frustum.b.distance (center) < -dia) return;
159 if (ctx.frustum.l.distance (center) < -dia) return; 143 if (ctx.frustum.l.distance (center) < -dia) return;
160 if (ctx.frustum.r.distance (center) < -dia) return; 144 if (ctx.frustum.r.distance (center) < -dia) return;
161 if (ctx.frustum.n.distance (center) < -dia) return; 145 if (ctx.frustum.n.distance (center) < -dia) return;
162 if (ctx.frustum.f.distance (center) < -dia) return; 146 if (ctx.frustum.f.distance (center) < -dia) return;
163#endif 147 }
164 148
149 if (size ())
150 ctx.vislist.push_back (this);
151
152 // node to start with
153 unsigned char si = ctx.d.x < 0 ? 1 : 0
154 | ctx.d.y < 0 ? 2 : 0
155 | ctx.d.z < 0 ? 4 : 0;
156
157 // bit-toggle to find next child for front-to-back order
158 static unsigned char next[8]
159 = { 0, 0^1, 1^2, 2^4, 4^3, 3^5, 5^6, 6^7 };
160
161 for (int i = 0; i < 8; i++)
165 } 162 {
163 si ^= next[i];
166 164
165 if (sub[si])
166 sub[si]->detect_visibility (ctx);
167 }
168
169 vs.generation = ctx.generation;
170}
171
172void octant::display (view &ctx)
173{
167#if 1 174#if 0
168 glBegin (GL_LINES); 175 glBegin (GL_LINES);
169 sector s = orig; 176 sector s = orig;
170 s.x -= ctx.v.orig.x; 177 s.x -= ctx.orig.x;
171 s.y -= ctx.v.orig.y; 178 s.y -= ctx.orig.y;
172 s.z -= ctx.v.orig.z; 179 s.z -= ctx.orig.z;
173 vec3 clr(0, 0.8, 0); 180 vec3 clr(0, 0.8, 0);
174 glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, (const GLfloat*)&clr); 181 glMaterialfv (GL_FRONT_AND_BACK, GL_DIFFUSE, (const GLfloat*)&clr);
175 182
176 for (int i = 8; i--; ) 183 for (int i = 8; i--; )
177 for (int ji = 3; ji--; ) 184 for (int ji = 3; ji--; )
190 197
191 glEnd (); 198 glEnd ();
192 glDisable(GL_COLOR_MATERIAL); 199 glDisable(GL_COLOR_MATERIAL);
193#endif 200#endif
194 201
195#if 0 202 GLuint i = begin_occ_query ();
196 if (vs.visibility == visibility_state::PARTIAL
197 && vs.generation == ctx.generation)
198#endif
199 {
200 for (iterator i = end (); i-- != begin (); ) 203 for (iterator i = end (); i != begin (); )
201#if 0
202 printf ("draw %p %d,%d,%d (%d,%d,%d - %d,%d,%d)\n", *i,
203 (*i)->orig.x,
204 (*i)->orig.y,
205 (*i)->orig.z,
206 (*i)->bbox.a.x,
207 (*i)->bbox.a.y,
208 (*i)->bbox.a.z,
209 (*i)->bbox.b.x,
210 (*i)->bbox.b.y,
211 (*i)->bbox.b.z
212 ),
213#endif
214 (*i)->display (ctx); 204 (*--i)->display (ctx);
215 205 end_occ_query ();
216 // node to start with
217 unsigned char si = ctx.v.d.x < 0 ? 1 : 0
218 | ctx.v.d.y < 0 ? 2 : 0
219 | ctx.v.d.z < 0 ? 4 : 0;
220
221 // bit-toggle to find next child for front-to-back order
222 static unsigned char next[8]
223 = { 0, 0^1, 1^2, 2^4, 4^3, 3^5, 5^6, 6^7 };
224
225 for (int i = 0; i < 8; i++)
226 {
227 si ^= next[i];
228
229 if (sub[si])
230 sub[si]->draw (ctx);
231 }
232 }
233
234 vs.generation = ctx.generation;
235} 206}
236 207
237 208
238 209

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines