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

Comparing libgender/oct.C (file contents):
Revision 1.55 by root, Sat Oct 16 23:28:22 2004 UTC vs.
Revision 1.56 by root, Sun Oct 17 09:43:07 2004 UTC

7 7
8#include "oct.h" 8#include "oct.h"
9#include "view.h" 9#include "view.h"
10#include "entity.h" 10#include "entity.h"
11 11
12enum visibility_state { FULL, PARTIAL, SMALL, OCCLUDED };
13
12struct evis { 14struct evis {
13 enum { FULL, SMALL, OCCLUDED } state; 15 visibility_state state;
14 double last; // time of last check 16 double last; // time of last check
15 evis () : last(0.), state(FULL) { }; 17 evis () : last(0.), state(FULL) { };
16}; 18};
17 19
18struct oct_visibility : visibility_base 20struct oct_visibility : visibility_base
19{ 21{
20 typedef map<entity *, evis> evismap; 22 typedef map<entity *, evis> evismap;
21 evismap vismap; 23 evismap vismap;
22 24
23 enum { FULL, PARTIAL, OCCLUDED } state; 25 visibility_state state;
24 26
25 oct_visibility (octant &oct) 27 oct_visibility (octant &oct)
26 : state(FULL) 28 : state(FULL)
27 { 29 {
28 } 30 }
114 point centerf = point (centeri) + ((extent & 1) ? 0.5F : 0.F); 116 point centerf = point (centeri) + ((extent & 1) ? 0.5F : 0.F);
115 117
116 GLfloat rad = ctx.diagfact * extent2; 118 GLfloat rad = ctx.diagfact * extent2;
117 119
118 if (orig <= ctx.orig && ctx.orig <= orig + extent) 120 if (orig <= ctx.orig && ctx.orig <= orig + extent)
119 ;//vs.visibility = visibility_state::PARTIAL; 121 vs.state = PARTIAL;
120 else 122 else
121 { 123 {
122 if (ctx.frustum.t.distance (centerf) < -rad) return false; 124 if (ctx.frustum.t.distance (centerf) < -rad) return false;
123 if (ctx.frustum.b.distance (centerf) < -rad) return false; 125 if (ctx.frustum.b.distance (centerf) < -rad) return false;
124 if (ctx.frustum.l.distance (centerf) < -rad) return false; 126 if (ctx.frustum.l.distance (centerf) < -rad) return false;
129 131
130 if (fd < -(ctx.c_far - ctx.z_far) -rad * 3.F) 132 if (fd < -(ctx.c_far - ctx.z_far) -rad * 3.F)
131 return false; 133 return false;
132 } 134 }
133 135
134#if 0 136 if (vs.state == OCCLUDED)
135 if (vs.visibility == visibility_state::OCCLUDED 137 return false;
136 || vs.visibility == visibility_state::UNKNOWN)
137 {
138 ctx.farlist.push_back (this);
139 return;
140 }
141#endif
142
143#if 0
144 if (vs.visibility == visibility_state::UNKNOWN)
145 vs.visibility = visibility_state::FULL;
146#endif
147 138
148 GLfloat z = ctx.z_near + ctx.frustum.n.distance (centerf) + rad; 139 GLfloat z = ctx.z_near + ctx.frustum.n.distance (centerf) + rad;
149 //printf ("z %f, perspfact %f, z*p %f\n", z, ctx.perspfact, ctx.perspfact / z); 140 //printf ("z %f, perspfact %f, z*p %f\n", z, ctx.perspfact, ctx.perspfact / z);
150 141
151#if 0 142 if (vs.state == PARTIAL || vs.state == FULL)
152 if (vs.visibility == visibility_state::FULL)
153#endif
154 ctx.nc_far = max (ctx.nc_far, z); 143 ctx.nc_far = max (ctx.nc_far, z);
155 144
156 // node to start with 145 // node to start with
157 unsigned char si = centeri.x > 0 ? 1 : 0 146 unsigned char si = centeri.x > 0 ? 1 : 0
158 | centeri.y > 0 ? 2 : 0 147 | centeri.y > 0 ? 2 : 0
173 sub[si]->depth_pass (ctx); 162 sub[si]->depth_pass (ctx);
174 } 163 }
175 while (*++next); 164 while (*++next);
176 165
177 if (size () 166 if (size ()
178#if 0 167 && (vs.state == PARTIAL || vs.state == FULL))
179 && (vs.visibility == visibility_state::PARTIAL
180 || vs.visibility == visibility_state::FULL)
181#endif
182 )
183 { 168 {
184 ctx.nz_far = max (ctx.nz_far, z); 169 ctx.nz_far = max (ctx.nz_far, z);
185 display (ctx); 170 display (ctx);
186 ctx.vislist.push_back (this); 171 ctx.vislist.push_back (this);
187 } 172 }
215 200
216 glEnd (); 201 glEnd ();
217#endif 202#endif
218 oct_visibility &vs = *(oct_visibility *)get_visibility (ctx); 203 oct_visibility &vs = *(oct_visibility *)get_visibility (ctx);
219 204
220 for (iterator i = end (); i != begin (); ) 205 if (vs.state == OCCLUDED)
221 { 206 {
222 entity *e = *--i; 207 abort ();
223 evis &evs = vs.vismap[e];
224
225 sector center = ((e->a + e->b) >> 1) - ctx.orig;
226 GLfloat z = norm (vec3 (center));
227 ctx.pixfact = ctx.perspfact / z;
228
229 if (ctx.mode == view::POSTDEPTH) 208 if (ctx.pass == view::POSTDEPTH)
230 { 209 {
231 if (!vb_bbox) 210 if (!vb_bbox)
232 { 211 {
233 sector s = orig - ctx.orig; 212 sector s = orig - ctx.orig;
234 gl::gen_bbox (vb_bbox, s, s + extent); 213 gl::gen_bbox (vb_bbox, s, s + extent);
235 } 214 }
236 215
216 ctx.begin_occ_query (*this, 0);
237 //vb_bbox.draw (gl::bbox_mode, 0, gl::bbox_count); 217 vb_bbox.draw (gl::bbox_mode, 0, gl::bbox_count);
218 ctx.end_occ_query ();
238 } 219 }
220 }
221 else
222 {
223 for (iterator i = end (); i != begin (); )
224 {
225 entity *e = *--i;
226
227 if (!ctx.may_draw (e))
228 continue;
229
230 evis &evs = vs.vismap[e];
231
232 if (ctx.pass == view::POSTDEPTH)
233 {
234 if (evs.state == OCCLUDED)
235 {
236 if (!e->vb_bbox)
237 gl::gen_bbox (e->vb_bbox, e->a - ctx.orig, e->b - ctx.orig);
238
239 ctx.begin_occ_query (*this, e);
240 e->vb_bbox.draw (gl::bbox_mode, 0, gl::bbox_count);
241 ctx.end_occ_query ();
242 }
243 }
239 else 244 else
240 e->display (ctx); 245 {
246 if (evs.state != OCCLUDED)
247 {
248 sector center = ((e->a + e->b) >> 1) - ctx.orig;
249 GLfloat z = norm (vec3 (center));
250 ctx.pixfact = ctx.perspfact / z;
251
252 if (ctx.pass == view::DEPTH || evs.last + 1. > timer.now)
253 e->draw (ctx);
254 else
255 {
256 evs.last = timer.now;
257 ctx.begin_occ_query (*this, e);
258 e->draw (ctx);
259 ctx.end_occ_query ();
260 }
261 }
262 }
263 }
241 } 264 }
242} 265}
243 266
244#if 0 267#if 0
245void octant::draw_bbox (view &ctx) 268void octant::draw_bbox (view &ctx)
250} 273}
251#endif 274#endif
252 275
253void octant::event (occ_query &ev) 276void octant::event (occ_query &ev)
254{ 277{
278 oct_visibility &vs = *(oct_visibility *)get_visibility (ev.ctx);
279 entity *e = (entity *)ev.id;
280
281 if (e)
282 {
283 evis &evs = vs.vismap[e];
284 evs.state = ev.count ? FULL : OCCLUDED;
285 }
286 else
287 {
288 vs.state = ev.count ? FULL : OCCLUDED;
289 }
290
255#if 0 291#if 0
256 visibility_state &vs = ev.v.vismap[this]; 292 visibility_state &vs = ev.v.vismap[this];
257 293
258 vs.last = timer.now; 294 vs.last = timer.now;
259 vs.visibility = ev.r <= 0 295 vs.state = ev.r <= 0
260 ? visibility_state::OCCLUDED 296 ? visibility_state::OCCLUDED
261 : visibility_state::FULL; 297 : visibility_state::FULL;
262#endif 298#endif
263} 299}
264 300

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines