DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
portals.c File Reference
#include "quakedef.h"
#include "polygon.h"
#include "portals.h"
+ Include dependency graph for portals.c:

Go to the source code of this file.

Data Structures

struct  portalrecursioninfo_t
 

Macros

#define MAXRECURSIVEPORTALPLANES   1024
 
#define MAXRECURSIVEPORTALS   256
 
#define Portal_MaxsBoxPolygon(axis, axisvalue, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
 
#define Portal_MinsBoxPolygon(axis, axisvalue, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
 

Functions

int Portal_CheckBox (model_t *model, vec3_t eye, vec3_t a, vec3_t b)
 
int Portal_CheckPolygon (model_t *model, vec3_t eye, float *polypoints, int numpoints)
 
static void Portal_PolygonRecursiveMarkLeafs (mnode_t *node, float *polypoints, int numpoints)
 
static int Portal_PortalThroughPortalPlanes (tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints)
 
static void Portal_RecursiveFindLeafForFlow (portalrecursioninfo_t *info, mnode_t *node)
 
static void Portal_RecursiveFlow (portalrecursioninfo_t *info, mleaf_t *leaf, int firstclipplane, int numclipplanes)
 
static int Portal_RecursiveFlowSearch (mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes)
 
void Portal_Visibility (model_t *model, const vec3_t eye, int *leaflist, unsigned char *leafpvs, int *numleafspointer, int *surfacelist, unsigned char *surfacepvs, int *numsurfacespointer, const mplane_t *frustumplanes, int numfrustumplanes, int exact, const float *boxmins, const float *boxmaxs, float *updateleafsmins, float *updateleafsmaxs, unsigned char *shadowtrispvs, unsigned char *lighttrispvs, unsigned char *visitingleafpvs)
 

Variables

static float boxpoints [4 *3]
 
static int portal_markid = 0
 
static tinyplane_t portalplanes [MAXRECURSIVEPORTALPLANES]
 
static float portaltemppoints [2][256][3]
 
static float portaltemppoints2 [256][3]
 
static int ranoutofportalplanes
 
static int ranoutofportals
 

Macro Definition Documentation

◆ MAXRECURSIVEPORTALPLANES

#define MAXRECURSIVEPORTALPLANES   1024

◆ MAXRECURSIVEPORTALS

#define MAXRECURSIVEPORTALS   256

Definition at line 7 of file portals.c.

Referenced by Portal_CheckPolygon(), and Portal_Visibility().

◆ Portal_MaxsBoxPolygon

#define Portal_MaxsBoxPolygon ( axis,
axisvalue,
x1,
y1,
z1,
x2,
y2,
z2,
x3,
y3,
z3,
x4,
y4,
z4 )
Value:
{\
if (eye[(axis)] > ((axisvalue) + 0.5f))\
{\
boxpoints[ 0] = x1;boxpoints[ 1] = y1;boxpoints[ 2] = z1;\
boxpoints[ 3] = x2;boxpoints[ 4] = y2;boxpoints[ 5] = z2;\
boxpoints[ 6] = x3;boxpoints[ 7] = y3;boxpoints[ 8] = z3;\
boxpoints[ 9] = x4;boxpoints[10] = y4;boxpoints[11] = z4;\
return true;\
}\
}
string model
static float boxpoints[4 *3]
Definition portals.c:15
int Portal_CheckPolygon(model_t *model, vec3_t eye, float *polypoints, int numpoints)
Definition portals.c:131
vec3 x4
vec3 x3
vec3 y2
vec3 x2
vec3 x1

Definition at line 195 of file portals.c.

195#define Portal_MaxsBoxPolygon(axis, axisvalue, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4) \
196{\
197 if (eye[(axis)] > ((axisvalue) + 0.5f))\
198 {\
199 boxpoints[ 0] = x1;boxpoints[ 1] = y1;boxpoints[ 2] = z1;\
200 boxpoints[ 3] = x2;boxpoints[ 4] = y2;boxpoints[ 5] = z2;\
201 boxpoints[ 6] = x3;boxpoints[ 7] = y3;boxpoints[ 8] = z3;\
202 boxpoints[ 9] = x4;boxpoints[10] = y4;boxpoints[11] = z4;\
203 if (Portal_CheckPolygon(model, eye, boxpoints, 4))\
204 return true;\
205 }\
206}

Referenced by Portal_CheckBox().

◆ Portal_MinsBoxPolygon

#define Portal_MinsBoxPolygon ( axis,
axisvalue,
x1,
y1,
z1,
x2,
y2,
z2,
x3,
y3,
z3,
x4,
y4,
z4 )
Value:
{\
if (eye[(axis)] < ((axisvalue) - 0.5f))\
{\
boxpoints[ 0] = x1;boxpoints[ 1] = y1;boxpoints[ 2] = z1;\
boxpoints[ 3] = x2;boxpoints[ 4] = y2;boxpoints[ 5] = z2;\
boxpoints[ 6] = x3;boxpoints[ 7] = y3;boxpoints[ 8] = z3;\
boxpoints[ 9] = x4;boxpoints[10] = y4;boxpoints[11] = z4;\
return true;\
}\
}

Definition at line 182 of file portals.c.

182#define Portal_MinsBoxPolygon(axis, axisvalue, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4) \
183{\
184 if (eye[(axis)] < ((axisvalue) - 0.5f))\
185 {\
186 boxpoints[ 0] = x1;boxpoints[ 1] = y1;boxpoints[ 2] = z1;\
187 boxpoints[ 3] = x2;boxpoints[ 4] = y2;boxpoints[ 5] = z2;\
188 boxpoints[ 6] = x3;boxpoints[ 7] = y3;boxpoints[ 8] = z3;\
189 boxpoints[ 9] = x4;boxpoints[10] = y4;boxpoints[11] = z4;\
190 if (Portal_CheckPolygon(model, eye, boxpoints, 4))\
191 return true;\
192 }\
193}

Referenced by Portal_CheckBox().

Function Documentation

◆ Portal_CheckBox()

int Portal_CheckBox ( model_t * model,
vec3_t eye,
vec3_t a,
vec3_t b )

Definition at line 208 of file portals.c.

209{
210 if (eye[0] >= (a[0] - 1.0f) && eye[0] < (b[0] + 1.0f)
211 && eye[1] >= (a[1] - 1.0f) && eye[1] < (b[1] + 1.0f)
212 && eye[2] >= (a[2] - 1.0f) && eye[2] < (b[2] + 1.0f))
213 return true;
214
216 (
217 0, a[0],
218 a[0], a[1], a[2],
219 a[0], b[1], a[2],
220 a[0], b[1], b[2],
221 a[0], a[1], b[2]
222 );
224 (
225 0, b[0],
226 b[0], b[1], a[2],
227 b[0], a[1], a[2],
228 b[0], a[1], b[2],
229 b[0], b[1], b[2]
230 );
232 (
233 1, a[1],
234 b[0], a[1], a[2],
235 a[0], a[1], a[2],
236 a[0], a[1], b[2],
237 b[0], a[1], b[2]
238 );
240 (
241 1, b[1],
242 a[0], b[1], a[2],
243 b[0], b[1], a[2],
244 b[0], b[1], b[2],
245 a[0], b[1], b[2]
246 );
248 (
249 2, a[2],
250 a[0], a[1], a[2],
251 b[0], a[1], a[2],
252 b[0], b[1], a[2],
253 a[0], b[1], a[2]
254 );
256 (
257 2, b[2],
258 b[0], a[1], b[2],
259 a[0], a[1], b[2],
260 a[0], b[1], b[2],
261 b[0], b[1], b[2]
262 );
263
264 return false;
265}
#define Portal_MinsBoxPolygon(axis, axisvalue, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
Definition portals.c:182
#define Portal_MaxsBoxPolygon(axis, axisvalue, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4)
Definition portals.c:195
dp_FragColor b
ret a

References a, b, Portal_MaxsBoxPolygon, and Portal_MinsBoxPolygon.

◆ Portal_CheckPolygon()

int Portal_CheckPolygon ( model_t * model,
vec3_t eye,
float * polypoints,
int numpoints )

Definition at line 131 of file portals.c.

132{
133 int i, prev, returnvalue;
134 mleaf_t *eyeleaf;
135 vec3_t center, v1, v2;
136
137 // if there is no model, it can not block visibility
138 if (model == NULL || !model->brush.PointInLeaf)
139 return true;
140
142
143 Portal_PolygonRecursiveMarkLeafs(model->brush.data_nodes, polypoints, numpoints);
144
145 eyeleaf = model->brush.PointInLeaf(model, eye);
146
147 // find the center by averaging
148 VectorClear(center);
149 for (i = 0;i < numpoints;i++)
150 VectorAdd(center, (&polypoints[i * 3]), center);
151 // ixtable is a 1.0f / N table
152 VectorScale(center, ixtable[numpoints], center);
153
154 // calculate the planes, and make sure the polygon can see it's own center
155 for (prev = numpoints - 1, i = 0;i < numpoints;prev = i, i++)
156 {
157 VectorSubtract(eye, (&polypoints[i * 3]), v1);
158 VectorSubtract((&polypoints[prev * 3]), (&polypoints[i * 3]), v2);
162 if (DotProduct(portalplanes[i].normal, center) <= portalplanes[i].dist)
163 {
164 // polygon can't see it's own center, discard
165 return false;
166 }
167 }
168
169 ranoutofportalplanes = false;
170 ranoutofportals = false;
171
172 returnvalue = Portal_RecursiveFlowSearch(eyeleaf, eye, 0, numpoints);
173
175 Con_Printf("Portal_RecursiveFlowSearch: ran out of %d plane stack when recursing through portals\n", MAXRECURSIVEPORTALPLANES);
176 if (ranoutofportals)
177 Con_Printf("Portal_RecursiveFlowSearch: ran out of %d portal stack when recursing through portals\n", MAXRECURSIVEPORTALS);
178
179 return returnvalue;
180}
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
GLfloat GLfloat GLfloat v2
Definition glquake.h:747
GLfloat GLfloat v1
Definition glquake.h:743
float ixtable[4096]
Definition mathlib.c:27
#define VectorNormalize(v)
Definition mathlib.h:104
#define VectorClear(a)
Definition mathlib.h:97
#define VectorSubtract(a, b, out)
Definition mathlib.h:99
#define CrossProduct(a, b, out)
Definition mathlib.h:103
#define DotProduct(a, b)
Definition mathlib.h:98
#define VectorScale(in, scale, out)
Definition mathlib.h:111
#define VectorAdd(a, b, out)
Definition mathlib.h:100
static int ranoutofportals
Definition portals.c:11
static int ranoutofportalplanes
Definition portals.c:10
#define MAXRECURSIVEPORTALS
Definition portals.c:7
static tinyplane_t portalplanes[MAXRECURSIVEPORTALPLANES]
Definition portals.c:9
static int portal_markid
Definition portals.c:14
#define MAXRECURSIVEPORTALPLANES
Definition portals.c:6
static void Portal_PolygonRecursiveMarkLeafs(mnode_t *node, float *polypoints, int numpoints)
Definition portals.c:99
static int Portal_RecursiveFlowSearch(mleaf_t *leaf, vec3_t eye, int firstclipplane, int numclipplanes)
Definition portals.c:38
int i
#define NULL
Definition qtypes.h:12
vec_t vec3_t[3]
Definition qtypes.h:71
vec3 normal
float dist
Definition mathlib.h:262

References Con_Printf(), CrossProduct, tinyplane_t::dist, DotProduct, i, ixtable, MAXRECURSIVEPORTALPLANES, MAXRECURSIVEPORTALS, model, normal, NULL, portal_markid, Portal_PolygonRecursiveMarkLeafs(), Portal_RecursiveFlowSearch(), portalplanes, ranoutofportalplanes, ranoutofportals, v1, v2, VectorAdd, VectorClear, VectorNormalize, VectorScale, and VectorSubtract.

◆ Portal_PolygonRecursiveMarkLeafs()

static void Portal_PolygonRecursiveMarkLeafs ( mnode_t * node,
float * polypoints,
int numpoints )
static

Definition at line 99 of file portals.c.

100{
101 int i, front;
102 float *p;
103
104loc0:
105 if (!node->plane)
106 {
107 ((mleaf_t *)node)->portalmarkid = portal_markid;
108 return;
109 }
110
111 front = 0;
112 for (i = 0, p = polypoints;i < numpoints;i++, p += 3)
113 {
114 if (DotProduct(p, node->plane->normal) > node->plane->dist)
115 front++;
116 }
117 if (front > 0)
118 {
119 if (front == numpoints)
120 {
121 node = node->children[0];
122 goto loc0;
123 }
124 else
125 Portal_PolygonRecursiveMarkLeafs(node->children[0], polypoints, numpoints);
126 }
127 node = node->children[1];
128 goto loc0;
129}
struct mnode_s * children[2]
mplane_t * plane
vec3_t normal
Definition model_brush.h:59
vec_t dist
Definition model_brush.h:60

References mnode_t::children, mplane_t::dist, DotProduct, i, mplane_t::normal, mnode_t::plane, portal_markid, and Portal_PolygonRecursiveMarkLeafs().

Referenced by Portal_CheckPolygon(), and Portal_PolygonRecursiveMarkLeafs().

◆ Portal_PortalThroughPortalPlanes()

static int Portal_PortalThroughPortalPlanes ( tinyplane_t * clipplanes,
int clipnumplanes,
float * targpoints,
int targnumpoints,
float * out,
int maxpoints )
static

Definition at line 17 of file portals.c.

18{
19 int numpoints = targnumpoints, i, w;
20 if (numpoints < 1)
21 return numpoints;
22 if (maxpoints > 256)
23 maxpoints = 256;
24 w = 0;
25 memcpy(&portaltemppoints[w][0][0], targpoints, numpoints * 3 * sizeof(float));
27 {
28 PolygonF_Divide(numpoints, &portaltemppoints[w][0][0], clipplanes[i].normal[0], clipplanes[i].normal[1], clipplanes[i].normal[2], clipplanes[i].dist, 1.0f/32.0f, 256, &portaltemppoints[1-w][0][0], &numpoints, 0, NULL, NULL, NULL);
29 w = 1-w;
30 numpoints = min(numpoints, 256);
31 }
32 numpoints = min(numpoints, maxpoints);
33 if (numpoints > 0)
34 memcpy(out, &portaltemppoints[w][0][0], numpoints * 3 * sizeof(float));
35 return numpoints;
36}
GLubyte GLubyte GLubyte GLubyte w
Definition glquake.h:782
#define min(A, B)
Definition mathlib.h:37
void PolygonF_Divide(int innumpoints, const float *inpoints, float planenormalx, float planenormaly, float planenormalz, float planedist, float epsilon, int outfrontmaxpoints, float *outfrontpoints, int *neededfrontpoints, int outbackmaxpoints, float *outbackpoints, int *neededbackpoints, int *oncountpointer)
Definition polygon.c:179
static float portaltemppoints[2][256][3]
Definition portals.c:12

References i, min, normal, NULL, PolygonF_Divide(), portaltemppoints, and w.

Referenced by Portal_RecursiveFlow(), and Portal_RecursiveFlowSearch().

◆ Portal_RecursiveFindLeafForFlow()

static void Portal_RecursiveFindLeafForFlow ( portalrecursioninfo_t * info,
mnode_t * node )
static

Definition at line 405 of file portals.c.

406{
407 if (node->plane)
408 {
409 float f = DotProduct(info->eye, node->plane->normal) - node->plane->dist;
410 if (f > -0.1)
412 if (f < 0.1)
414 }
415 else
416 {
417 mleaf_t *leaf = (mleaf_t *)node;
418 if (leaf->clusterindex >= 0)
419 Portal_RecursiveFlow(info, leaf, 0, info->numfrustumplanes);
420 }
421}
static void Portal_RecursiveFindLeafForFlow(portalrecursioninfo_t *info, mnode_t *node)
Definition portals.c:405
static void Portal_RecursiveFlow(portalrecursioninfo_t *info, mleaf_t *leaf, int firstclipplane, int numclipplanes)
Definition portals.c:289
float f
int clusterindex

References mnode_t::children, mleaf_t::clusterindex, mplane_t::dist, DotProduct, portalrecursioninfo_t::eye, f, mplane_t::normal, portalrecursioninfo_t::numfrustumplanes, mnode_t::plane, Portal_RecursiveFindLeafForFlow(), and Portal_RecursiveFlow().

Referenced by Portal_RecursiveFindLeafForFlow(), and Portal_Visibility().

◆ Portal_RecursiveFlow()

static void Portal_RecursiveFlow ( portalrecursioninfo_t * info,
mleaf_t * leaf,
int firstclipplane,
int numclipplanes )
static

Definition at line 289 of file portals.c.

290{
291 mportal_t *p;
292 int newpoints, i, prev;
293 float dist;
294 vec3_t center;
295 tinyplane_t *newplanes;
296 int leafindex = leaf - info->model->brush.data_leafs;
297
298 if (CHECKPVSBIT(info->visitingleafpvs, leafindex))
299 return; // recursive loop of leafs (cmc.bsp for megatf coop)
300
301 SETPVSBIT(info->visitingleafpvs, leafindex);
302
303 for (i = 0;i < 3;i++)
304 {
305 if (info->updateleafsmins && info->updateleafsmins[i] > leaf->mins[i]) info->updateleafsmins[i] = leaf->mins[i];
306 if (info->updateleafsmaxs && info->updateleafsmaxs[i] < leaf->maxs[i]) info->updateleafsmaxs[i] = leaf->maxs[i];
307 }
308
309
310 if (info->leafpvs)
311 {
312 if (!CHECKPVSBIT(info->leafpvs, leafindex))
313 {
314 SETPVSBIT(info->leafpvs, leafindex);
315 info->leaflist[info->numleafs++] = leafindex;
316 }
317 }
318
319 // mark surfaces in leaf that can be seen through portal
320 if (leaf->numleafsurfaces && info->surfacepvs)
321 {
322 for (i = 0;i < leaf->numleafsurfaces;i++)
323 {
324 int surfaceindex = leaf->firstleafsurface[i];
325 msurface_t *surface = info->model->data_surfaces + surfaceindex;
326 if (BoxesOverlap(surface->mins, surface->maxs, info->boxmins, info->boxmaxs))
327 {
328 qbool insidebox = BoxInsideBox(surface->mins, surface->maxs, info->boxmins, info->boxmaxs);
329 qbool addedtris = false;
330 int t, tend;
331 const int *elements;
332 const float *vertex3f;
333 float v[9];
334 vertex3f = info->model->surfmesh.data_vertex3f;
335 elements = (info->model->surfmesh.data_element3i + 3 * surface->num_firsttriangle);
336 for (t = surface->num_firsttriangle, tend = t + surface->num_triangles;t < tend;t++, elements += 3)
337 {
338 VectorCopy(vertex3f + elements[0] * 3, v + 0);
339 VectorCopy(vertex3f + elements[1] * 3, v + 3);
340 VectorCopy(vertex3f + elements[2] * 3, v + 6);
341 if (PointInfrontOfTriangle(info->eye, v + 0, v + 3, v + 6)
342 && (insidebox || TriangleBBoxOverlapsBox(v, v + 3, v + 6, info->boxmins, info->boxmaxs))
343 && (!info->exact || Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, v, 3, &portaltemppoints2[0][0], 256) > 0))
344 {
345 addedtris = true;
346 if (info->shadowtrispvs)
347 SETPVSBIT(info->shadowtrispvs, t);
348 if (info->lighttrispvs)
349 SETPVSBIT(info->lighttrispvs, t);
350 }
351 }
352 if (addedtris && !CHECKPVSBIT(info->surfacepvs, surfaceindex))
353 {
354 SETPVSBIT(info->surfacepvs, surfaceindex);
355 info->surfacelist[info->numsurfaces++] = surfaceindex;
356 }
357 }
358 }
359 }
360
361 // follow portals into other leafs
362 for (p = leaf->portals;p;p = p->next)
363 {
364 // only flow through portals facing the viewer
365 dist = PlaneDiff(info->eye, (&p->plane));
366 if (dist < 0 && BoxesOverlap(p->past->mins, p->past->maxs, info->boxmins, info->boxmaxs))
367 {
368 newpoints = Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, (float *) p->points, p->numpoints, &portaltemppoints2[0][0], 256);
369 if (newpoints < 3)
370 continue;
371 else if (firstclipplane + numclipplanes + newpoints > MAXRECURSIVEPORTALPLANES)
373 else
374 {
375 // find the center by averaging
376 VectorClear(center);
377 for (i = 0;i < newpoints;i++)
378 VectorAdd(center, portaltemppoints2[i], center);
379 // ixtable is a 1.0f / N table
380 VectorScale(center, ixtable[newpoints], center);
381 // calculate the planes, and make sure the polygon can see its own center
382 newplanes = &portalplanes[firstclipplane + numclipplanes];
383 for (prev = newpoints - 1, i = 0;i < newpoints;prev = i, i++)
384 {
385 TriangleNormal(portaltemppoints2[prev], portaltemppoints2[i], info->eye, newplanes[i].normal);
386 VectorNormalize(newplanes[i].normal);
387 newplanes[i].dist = DotProduct(info->eye, newplanes[i].normal);
388 if (DotProduct(newplanes[i].normal, center) <= newplanes[i].dist)
389 {
390 // polygon can't see its own center, discard and use parent portal
391 break;
392 }
393 }
394 if (i == newpoints)
395 Portal_RecursiveFlow(info, p->past, firstclipplane + numclipplanes, newpoints);
396 else
397 Portal_RecursiveFlow(info, p->past, firstclipplane, numclipplanes);
398 }
399 }
400 }
401
402 CLEARPVSBIT(info->visitingleafpvs, leafindex);
403}
const GLdouble * v
Definition glquake.h:762
#define BoxesOverlap(a, b, c, d)
Definition mathlib.h:122
#define BoxInsideBox(a, b, c, d)
Definition mathlib.h:123
#define PointInfrontOfTriangle(p, a, b, c)
Definition mathlib.h:143
#define TriangleNormal(a, b, c, n)
Definition mathlib.h:126
#define PlaneDiff(point, plane)
Definition mathlib.h:257
#define VectorCopy(in, out)
Definition mathlib.h:101
#define TriangleBBoxOverlapsBox(a, b, c, d, e)
Definition mathlib.h:124
#define CLEARPVSBIT(pvs, b)
#define CHECKPVSBIT(pvs, b)
#define SETPVSBIT(pvs, b)
static int Portal_PortalThroughPortalPlanes(tinyplane_t *clipplanes, int clipnumplanes, float *targpoints, int targnumpoints, float *out, int maxpoints)
Definition portals.c:17
static float portaltemppoints2[256][3]
Definition portals.c:13
bool qbool
Definition qtypes.h:9
vec3_t mins
int * firstleafsurface
vec3_t maxs
int numleafsurfaces
struct mportal_s * portals
mleaf_t * data_leafs
model_brush_t brush
surfmesh_t surfmesh
msurface_t * data_surfaces
mvertex_t * points
struct mportal_s * next
mleaf_t * past
mplane_t plane
describes the textures to use on a range of triangles in the model, and mins/maxs (AABB) for culling.
int num_firsttriangle
int num_triangles
range of triangles and vertices in model->surfmesh
vec3_t mins
bounding box for onscreen checks
unsigned char * leafpvs
Definition portals.c:279
unsigned char * shadowtrispvs
Definition portals.c:280
float * updateleafsmins
Definition portals.c:284
unsigned char * lighttrispvs
Definition portals.c:281
float * updateleafsmaxs
Definition portals.c:285
unsigned char * surfacepvs
Definition portals.c:275
unsigned char * visitingleafpvs
Definition portals.c:277
int * data_element3i
float * data_vertex3f
LadyHavoc: minimal plane structure.
Definition mathlib.h:261

References BoxesOverlap, BoxInsideBox, portalrecursioninfo_t::boxmaxs, portalrecursioninfo_t::boxmins, model_t::brush, CHECKPVSBIT, CLEARPVSBIT, surfmesh_t::data_element3i, model_brush_t::data_leafs, model_t::data_surfaces, surfmesh_t::data_vertex3f, tinyplane_t::dist, DotProduct, portalrecursioninfo_t::exact, portalrecursioninfo_t::eye, mleaf_t::firstleafsurface, i, ixtable, portalrecursioninfo_t::leaflist, portalrecursioninfo_t::leafpvs, portalrecursioninfo_t::lighttrispvs, MAXRECURSIVEPORTALPLANES, mleaf_t::maxs, msurface_t::maxs, mleaf_t::mins, msurface_t::mins, portalrecursioninfo_t::model, mportal_t::next, normal, tinyplane_t::normal, msurface_t::num_firsttriangle, msurface_t::num_triangles, portalrecursioninfo_t::numleafs, mleaf_t::numleafsurfaces, mportal_t::numpoints, portalrecursioninfo_t::numsurfaces, mportal_t::past, mportal_t::plane, PlaneDiff, PointInfrontOfTriangle, mportal_t::points, Portal_PortalThroughPortalPlanes(), Portal_RecursiveFlow(), portalplanes, mleaf_t::portals, portaltemppoints2, ranoutofportalplanes, SETPVSBIT, portalrecursioninfo_t::shadowtrispvs, portalrecursioninfo_t::surfacelist, portalrecursioninfo_t::surfacepvs, model_t::surfmesh, TriangleBBoxOverlapsBox, TriangleNormal, portalrecursioninfo_t::updateleafsmaxs, portalrecursioninfo_t::updateleafsmins, v, VectorAdd, VectorClear, VectorCopy, VectorNormalize, VectorScale, and portalrecursioninfo_t::visitingleafpvs.

Referenced by Portal_RecursiveFindLeafForFlow(), and Portal_RecursiveFlow().

◆ Portal_RecursiveFlowSearch()

static int Portal_RecursiveFlowSearch ( mleaf_t * leaf,
vec3_t eye,
int firstclipplane,
int numclipplanes )
static

Definition at line 38 of file portals.c.

39{
40 mportal_t *p;
41 int newpoints, i, prev;
42 vec3_t center, v1, v2;
43 tinyplane_t *newplanes;
44
45 if (leaf->portalmarkid == portal_markid)
46 return true;
47
48 // follow portals into other leafs
49 for (p = leaf->portals;p;p = p->next)
50 {
51 // only flow through portals facing away from the viewer
52 if (PlaneDiff(eye, (&p->plane)) < 0)
53 {
54 newpoints = Portal_PortalThroughPortalPlanes(&portalplanes[firstclipplane], numclipplanes, (float *) p->points, p->numpoints, &portaltemppoints2[0][0], 256);
55 if (newpoints < 3)
56 continue;
57 else if (firstclipplane + numclipplanes + newpoints > MAXRECURSIVEPORTALPLANES)
59 else
60 {
61 // find the center by averaging
62 VectorClear(center);
63 for (i = 0;i < newpoints;i++)
64 VectorAdd(center, portaltemppoints2[i], center);
65 // ixtable is a 1.0f / N table
66 VectorScale(center, ixtable[newpoints], center);
67 // calculate the planes, and make sure the polygon can see it's own center
68 newplanes = &portalplanes[firstclipplane + numclipplanes];
69 for (prev = newpoints - 1, i = 0;i < newpoints;prev = i, i++)
70 {
73 CrossProduct(v1, v2, newplanes[i].normal);
74 VectorNormalize(newplanes[i].normal);
75 newplanes[i].dist = DotProduct(eye, newplanes[i].normal);
76 if (DotProduct(newplanes[i].normal, center) <= newplanes[i].dist)
77 {
78 // polygon can't see it's own center, discard and use parent portal
79 break;
80 }
81 }
82 if (i == newpoints)
83 {
84 if (Portal_RecursiveFlowSearch(p->past, eye, firstclipplane + numclipplanes, newpoints))
85 return true;
86 }
87 else
88 {
89 if (Portal_RecursiveFlowSearch(p->past, eye, firstclipplane, numclipplanes))
90 return true;
91 }
92 }
93 }
94 }
95
96 return false;
97}
int portalmarkid

References CrossProduct, tinyplane_t::dist, DotProduct, i, ixtable, MAXRECURSIVEPORTALPLANES, mportal_t::next, normal, mportal_t::numpoints, mportal_t::past, mportal_t::plane, PlaneDiff, mportal_t::points, portal_markid, Portal_PortalThroughPortalPlanes(), Portal_RecursiveFlowSearch(), mleaf_t::portalmarkid, portalplanes, mleaf_t::portals, portaltemppoints2, ranoutofportalplanes, v1, v2, VectorAdd, VectorClear, VectorNormalize, VectorScale, and VectorSubtract.

Referenced by Portal_CheckPolygon(), and Portal_RecursiveFlowSearch().

◆ Portal_Visibility()

void Portal_Visibility ( model_t * model,
const vec3_t eye,
int * leaflist,
unsigned char * leafpvs,
int * numleafspointer,
int * surfacelist,
unsigned char * surfacepvs,
int * numsurfacespointer,
const mplane_t * frustumplanes,
int numfrustumplanes,
int exact,
const float * boxmins,
const float * boxmaxs,
float * updateleafsmins,
float * updateleafsmaxs,
unsigned char * shadowtrispvs,
unsigned char * lighttrispvs,
unsigned char * visitingleafpvs )

Definition at line 423 of file portals.c.

424{
425 int i;
427
428 // if there is no model, it can not block visibility
429 if (model == NULL)
430 {
431 Con_Print("Portal_Visibility: NULL model\n");
432 return;
433 }
434
435 if (!model->brush.data_nodes)
436 {
437 Con_Print("Portal_Visibility: not a brush model\n");
438 return;
439 }
440
441 // put frustum planes (if any) into tinyplane format at start of buffer
442 for (i = 0;i < numfrustumplanes;i++)
443 {
444 VectorCopy(frustumplanes[i].normal, portalplanes[i].normal);
445 portalplanes[i].dist = frustumplanes[i].dist;
446 }
447
448 ranoutofportalplanes = false;
449 ranoutofportals = false;
450
451 VectorCopy(boxmins, info.boxmins);
452 VectorCopy(boxmaxs, info.boxmaxs);
453 info.exact = exact;
454 info.numsurfaces = 0;
455 info.surfacelist = surfacelist;
456 info.surfacepvs = surfacepvs;
457 info.numleafs = 0;
458 info.visitingleafpvs = visitingleafpvs;
459 info.leaflist = leaflist;
460 info.leafpvs = leafpvs;
461 info.model = model;
462 VectorCopy(eye, info.eye);
463 info.numfrustumplanes = numfrustumplanes;
464 info.updateleafsmins = updateleafsmins;
465 info.updateleafsmaxs = updateleafsmaxs;
466 info.shadowtrispvs = shadowtrispvs;
467 info.lighttrispvs = lighttrispvs;
468
469 Portal_RecursiveFindLeafForFlow(&info, model->brush.data_nodes);
470
472 Con_Printf("Portal_RecursiveFlow: ran out of %d plane stack when recursing through portals\n", MAXRECURSIVEPORTALPLANES);
473 if (ranoutofportals)
474 Con_Printf("Portal_RecursiveFlow: ran out of %d portal stack when recursing through portals\n", MAXRECURSIVEPORTALS);
475 if (numsurfacespointer)
476 *numsurfacespointer = info.numsurfaces;
477 if (numleafspointer)
478 *numleafspointer = info.numleafs;
479}
void Con_Print(const char *msg)
Prints to all appropriate console targets, and adds timestamps.
Definition console.c:1504

References portalrecursioninfo_t::boxmaxs, portalrecursioninfo_t::boxmins, Con_Print(), Con_Printf(), mplane_t::dist, tinyplane_t::dist, portalrecursioninfo_t::exact, portalrecursioninfo_t::eye, i, portalrecursioninfo_t::leaflist, portalrecursioninfo_t::leafpvs, portalrecursioninfo_t::lighttrispvs, MAXRECURSIVEPORTALPLANES, MAXRECURSIVEPORTALS, model, portalrecursioninfo_t::model, normal, NULL, portalrecursioninfo_t::numfrustumplanes, portalrecursioninfo_t::numleafs, portalrecursioninfo_t::numsurfaces, Portal_RecursiveFindLeafForFlow(), portalplanes, ranoutofportalplanes, ranoutofportals, portalrecursioninfo_t::shadowtrispvs, portalrecursioninfo_t::surfacelist, portalrecursioninfo_t::surfacepvs, portalrecursioninfo_t::updateleafsmaxs, portalrecursioninfo_t::updateleafsmins, VectorCopy, and portalrecursioninfo_t::visitingleafpvs.

Referenced by R_Mod_GetLightInfo().

Variable Documentation

◆ boxpoints

float boxpoints[4 *3]
static

Definition at line 15 of file portals.c.

◆ portal_markid

int portal_markid = 0
static

◆ portalplanes

◆ portaltemppoints

float portaltemppoints[2][256][3]
static

Definition at line 12 of file portals.c.

Referenced by Portal_PortalThroughPortalPlanes().

◆ portaltemppoints2

float portaltemppoints2[256][3]
static

Definition at line 13 of file portals.c.

Referenced by Portal_RecursiveFlow(), and Portal_RecursiveFlowSearch().

◆ ranoutofportalplanes

int ranoutofportalplanes
static

◆ ranoutofportals

int ranoutofportals
static

Definition at line 11 of file portals.c.

Referenced by Portal_CheckPolygon(), and Portal_Visibility().