DarkPlaces
Game engine based on the Quake 1 engine by id Software, developed by LadyHavoc
 
collision.h File Reference
#include "matrixlib.h"
+ Include dependency graph for collision.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  colboxbrushf_t
 
struct  colbrushf_t
 
struct  colplanef_t
 
struct  colpointf_t
 
union  plane_t
 
struct  trace_t
 

Macros

#define COLLISIONPARANOID   0
 

Functions

void Collision_BoundingBoxOfBrushTraceSegment (const colbrushf_t *start, const colbrushf_t *end, vec3_t mins, vec3_t maxs, float startfrac, float endfrac)
 
void Collision_BrushForBox (colboxbrushf_t *boxbrush, const vec3_t mins, const vec3_t maxs, int supercontents, int q3surfaceflags, const texture_t *texture)
 
void Collision_Cache_ClipLineToGenericEntitySurfaces (trace_t *trace, struct model_s *model, matrix4x4_t *matrix, matrix4x4_t *inversematrix, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask)
 
void Collision_Cache_ClipLineToWorldSurfaces (trace_t *trace, struct model_s *model, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask)
 
void Collision_Cache_Init (struct mempool_s *mempool)
 
void Collision_Cache_NewFrame (void)
 
void Collision_Cache_Reset (qbool resetlimits)
 
void Collision_CalcPlanesForTriangleBrushFloat (colbrushf_t *brush)
 
void Collision_ClipLineToGenericEntity (trace_t *trace, struct model_s *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, const vec3_t bodymins, const vec3_t bodymaxs, int bodysupercontents, matrix4x4_t *matrix, matrix4x4_t *inversematrix, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qbool hitsurfaces)
 
void Collision_ClipLineToWorld (trace_t *trace, struct model_s *model, const vec3_t start, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend, qbool hitsurfaces)
 
void Collision_ClipPointToGenericEntity (trace_t *trace, struct model_s *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, const vec3_t bodymins, const vec3_t bodymaxs, int bodysupercontents, matrix4x4_t *matrix, matrix4x4_t *inversematrix, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask)
 
void Collision_ClipPointToWorld (trace_t *trace, struct model_s *model, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask)
 
void Collision_ClipToGenericEntity (trace_t *trace, struct model_s *model, const struct frameblend_s *frameblend, const struct skeleton_s *skeleton, const vec3_t bodymins, const vec3_t bodymaxs, int bodysupercontents, matrix4x4_t *matrix, matrix4x4_t *inversematrix, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend)
 
void Collision_ClipToWorld (trace_t *trace, struct model_s *model, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, float extend)
 
void Collision_ClipTrace_Box (trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, const vec3_t mins, const vec3_t maxs, const vec3_t end, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, int boxsupercontents, int boxq3surfaceflags, const texture_t *boxtexture)
 
float Collision_ClipTrace_Line_Sphere (double *linestart, double *lineend, double *sphereorigin, double sphereradius, double *impactpoint, double *impactnormal)
 
void Collision_ClipTrace_Point (trace_t *trace, const vec3_t cmins, const vec3_t cmaxs, const vec3_t start, int hitsupercontentsmask, int skipsupercontentsmask, int skipmaterialflagsmask, int boxsupercontents, int boxq3surfaceflags, const texture_t *boxtexture)
 
void Collision_CombineTraces (trace_t *cliptrace, const trace_t *trace, void *touch, qbool isbmodel)
 
void Collision_Init (void)
 
colbrushf_tCollision_NewBrushFromPlanes (struct mempool_s *mempool, int numoriginalplanes, const colplanef_t *originalplanes, int supercontents, int q3surfaceflags, const texture_t *texture, int hasaabbplanes)
 
qbool Collision_PointInsideBrushFloat (const vec3_t point, const colbrushf_t *brush)
 
void Collision_TraceBrushBrushFloat (trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, const colbrushf_t *thatbrush_start, const colbrushf_t *thatbrush_end)
 
void Collision_TraceBrushTriangleFloat (trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, const float *v0, const float *v1, const float *v2, int supercontents, int q3surfaceflags, const texture_t *texture)
 
void Collision_TraceBrushTriangleMeshFloat (trace_t *trace, const colbrushf_t *thisbrush_start, const colbrushf_t *thisbrush_end, int numtriangles, const int *element3i, const float *vertex3f, int stride, float *bbox6f, int supercontents, int q3surfaceflags, const texture_t *texture, const vec3_t segmentmins, const vec3_t segmentmaxs)
 
void Collision_TraceLineBrushFloat (trace_t *trace, const vec3_t linestart, const vec3_t lineend, const colbrushf_t *thatbrush_start, const colbrushf_t *thatbrush_end)
 
void Collision_TraceLineTriangleFloat (trace_t *trace, const vec3_t linestart, const vec3_t lineend, const float *point0, const float *point1, const float *point2, int supercontents, int q3surfaceflags, const texture_t *texture)
 
void Collision_TraceLineTriangleMeshFloat (trace_t *trace, const vec3_t linestart, const vec3_t lineend, int numtriangles, const int *element3i, const float *vertex3f, int stride, float *bbox6f, int supercontents, int q3surfaceflags, const texture_t *texture, const vec3_t segmentmins, const vec3_t segmentmaxs)
 
void Collision_TracePointBrushFloat (trace_t *trace, const vec3_t point, const colbrushf_t *thatbrush)
 

Variables

struct cvar_s collision_bih_fullrecursion
 
struct cvar_s collision_extendmovelength
 
struct cvar_s collision_extendtraceboxlength
 
struct cvar_s collision_extendtracelinelength
 
struct cvar_s collision_impactnudge
 

Macro Definition Documentation

◆ COLLISIONPARANOID

#define COLLISIONPARANOID   0

Definition at line 195 of file collision.h.

Function Documentation

◆ Collision_BoundingBoxOfBrushTraceSegment()

void Collision_BoundingBoxOfBrushTraceSegment ( const colbrushf_t * start,
const colbrushf_t * end,
vec3_t mins,
vec3_t maxs,
float startfrac,
float endfrac )

Definition at line 1367 of file collision.c.

1368{
1369 int i;
1370 colpointf_t *ps, *pe;
1371 float tempstart[3], tempend[3];
1372 VectorLerp(start->points[0].v, startfrac, end->points[0].v, mins);
1374 for (i = 0, ps = start->points, pe = end->points;i < start->numpoints;i++, ps++, pe++)
1375 {
1376 VectorLerp(ps->v, startfrac, pe->v, tempstart);
1377 VectorLerp(ps->v, endfrac, pe->v, tempend);
1378 mins[0] = min(mins[0], min(tempstart[0], tempend[0]));
1379 mins[1] = min(mins[1], min(tempstart[1], tempend[1]));
1380 mins[2] = min(mins[2], min(tempstart[2], tempend[2]));
1381 maxs[0] = min(maxs[0], min(tempstart[0], tempend[0]));
1382 maxs[1] = min(maxs[1], min(tempstart[1], tempend[1]));
1383 maxs[2] = min(maxs[2], min(tempstart[2], tempend[2]));
1384 }
1385 mins[0] -= 1;
1386 mins[1] -= 1;
1387 mins[2] -= 1;
1388 maxs[0] += 1;
1389 maxs[1] += 1;
1390 maxs[2] += 1;
1391}
vector mins
vector maxs
#define VectorLerp(v1, lerp, v2, out)
Definition mathlib.h:120
#define min(A, B)
Definition mathlib.h:37
#define VectorCopy(in, out)
Definition mathlib.h:101
int i
colpointf_t * points
Definition collision.h:121
vec3_t v
Definition collision.h:84

References i, maxs, min, mins, colbrushf_t::points, colpointf_t::v, VectorCopy, and VectorLerp.

◆ Collision_BrushForBox()

void Collision_BrushForBox ( colboxbrushf_t * boxbrush,
const vec3_t mins,
const vec3_t maxs,
int supercontents,
int q3surfaceflags,
const texture_t * texture )

Definition at line 1141 of file collision.c.

1142{
1143 int i;
1144 memset(boxbrush, 0, sizeof(*boxbrush));
1145 boxbrush->brush.isaabb = true;
1146 boxbrush->brush.hasaabbplanes = true;
1147 boxbrush->brush.points = boxbrush->points;
1148 boxbrush->brush.edgedirs = boxbrush->edgedirs;
1149 boxbrush->brush.planes = boxbrush->planes;
1150 boxbrush->brush.supercontents = supercontents;
1151 boxbrush->brush.q3surfaceflags = q3surfaceflags;
1152 boxbrush->brush.texture = texture;
1153 if (VectorCompare(mins, maxs))
1154 {
1155 // point brush
1156 boxbrush->brush.numpoints = 1;
1157 boxbrush->brush.numedgedirs = 0;
1158 boxbrush->brush.numplanes = 0;
1159 VectorCopy(mins, boxbrush->brush.points[0].v);
1160 }
1161 else
1162 {
1163 boxbrush->brush.numpoints = 8;
1164 boxbrush->brush.numedgedirs = 3;
1165 boxbrush->brush.numplanes = 6;
1166 // there are 8 points on a box
1167 // there are 3 edgedirs on a box (both signs are tested in collision)
1168 // there are 6 planes on a box
1169 VectorSet(boxbrush->brush.points[0].v, mins[0], mins[1], mins[2]);
1170 VectorSet(boxbrush->brush.points[1].v, maxs[0], mins[1], mins[2]);
1171 VectorSet(boxbrush->brush.points[2].v, mins[0], maxs[1], mins[2]);
1172 VectorSet(boxbrush->brush.points[3].v, maxs[0], maxs[1], mins[2]);
1173 VectorSet(boxbrush->brush.points[4].v, mins[0], mins[1], maxs[2]);
1174 VectorSet(boxbrush->brush.points[5].v, maxs[0], mins[1], maxs[2]);
1175 VectorSet(boxbrush->brush.points[6].v, mins[0], maxs[1], maxs[2]);
1176 VectorSet(boxbrush->brush.points[7].v, maxs[0], maxs[1], maxs[2]);
1177 VectorSet(boxbrush->brush.edgedirs[0].v, 1, 0, 0);
1178 VectorSet(boxbrush->brush.edgedirs[1].v, 0, 1, 0);
1179 VectorSet(boxbrush->brush.edgedirs[2].v, 0, 0, 1);
1180 VectorSet(boxbrush->brush.planes[0].normal, -1, 0, 0);boxbrush->brush.planes[0].dist = -mins[0];
1181 VectorSet(boxbrush->brush.planes[1].normal, 1, 0, 0);boxbrush->brush.planes[1].dist = maxs[0];
1182 VectorSet(boxbrush->brush.planes[2].normal, 0, -1, 0);boxbrush->brush.planes[2].dist = -mins[1];
1183 VectorSet(boxbrush->brush.planes[3].normal, 0, 1, 0);boxbrush->brush.planes[3].dist = maxs[1];
1184 VectorSet(boxbrush->brush.planes[4].normal, 0, 0, -1);boxbrush->brush.planes[4].dist = -mins[2];
1185 VectorSet(boxbrush->brush.planes[5].normal, 0, 0, 1);boxbrush->brush.planes[5].dist = maxs[2];
1186 for (i = 0;i < 6;i++)
1187 {
1188 boxbrush->brush.planes[i].q3surfaceflags = q3surfaceflags;
1189 boxbrush->brush.planes[i].texture = texture;
1190 }
1191 }
1192 boxbrush->brush.supercontents = supercontents;
1193 boxbrush->brush.q3surfaceflags = q3surfaceflags;
1194 boxbrush->brush.texture = texture;
1195 VectorSet(boxbrush->brush.mins, mins[0] - 1, mins[1] - 1, mins[2] - 1);
1196 VectorSet(boxbrush->brush.maxs, maxs[0] + 1, maxs[1] + 1, maxs[2] + 1);
1197 //Collision_ValidateBrush(&boxbrush->brush);
1198}
GLenum GLenum GLuint texture
Definition glquake.h:613
#define VectorSet(vec, x, y, z)
Definition mathlib.h:96
#define VectorCompare(a, b)
Definition mathlib.h:113
colbrushf_t brush
Definition collision.h:139
colplanef_t planes[6]
Definition collision.h:138
colpointf_t edgedirs[6]
Definition collision.h:137
colpointf_t points[8]
Definition collision.h:136
colpointf_t * edgedirs
Definition collision.h:118
int hasaabbplanes
Definition collision.h:130
vec3_t mins
Definition collision.h:107
int q3surfaceflags
Definition collision.h:127
const struct texture_s * texture
Definition collision.h:126
colplanef_t * planes
Definition collision.h:115
int numedgedirs
Definition collision.h:117
int supercontents
Definition collision.h:112
vec3_t maxs
Definition collision.h:108
vec3_t normal
Definition collision.h:96
int q3surfaceflags
Definition collision.h:91
vec_t dist
Definition collision.h:97
const struct texture_s * texture
Definition collision.h:90

References colboxbrushf_t::brush, colplanef_t::dist, colboxbrushf_t::edgedirs, colbrushf_t::edgedirs, colbrushf_t::hasaabbplanes, i, colbrushf_t::isaabb, colbrushf_t::maxs, maxs, colbrushf_t::mins, mins, colplanef_t::normal, colbrushf_t::numedgedirs, colbrushf_t::numplanes, colbrushf_t::numpoints, colboxbrushf_t::planes, colbrushf_t::planes, colboxbrushf_t::points, colbrushf_t::points, colbrushf_t::q3surfaceflags, colplanef_t::q3surfaceflags, colbrushf_t::supercontents, colbrushf_t::texture, colplanef_t::texture, texture, colpointf_t::v, VectorCompare, VectorCopy, and VectorSet.

Referenced by Collision_ClipToGenericEntity(), Collision_TraceLineBrushFloat(), Mod_CollisionBIH_TraceBox(), and Mod_MDLMD2MD3_TraceBox().

◆ Collision_Cache_ClipLineToGenericEntitySurfaces()

void Collision_Cache_ClipLineToGenericEntitySurfaces ( trace_t * trace,
struct model_s * model,
matrix4x4_t * matrix,
matrix4x4_t * inversematrix,
const vec3_t start,
const vec3_t end,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask )

◆ Collision_Cache_ClipLineToWorldSurfaces()

void Collision_Cache_ClipLineToWorldSurfaces ( trace_t * trace,
struct model_s * model,
const vec3_t start,
const vec3_t end,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask )

◆ Collision_Cache_Init()

void Collision_Cache_Init ( struct mempool_s * mempool)

◆ Collision_Cache_NewFrame()

void Collision_Cache_NewFrame ( void )

Definition at line 1548 of file collision.c.

1549{
1551 {
1552 if (collision_cachedtrace_max < 128)
1554 }
1555 else
1556 {
1559 }
1560 // rebuild hash if sequence would overflow byte, otherwise increment
1562 {
1565 }
1566 else
1567 {
1570 }
1571}
static void Collision_Cache_RebuildHash(void)
Definition collision.c:1515
static int collision_cachedtrace_max
Definition collision.c:1470
void Collision_Cache_Reset(qbool resetlimits)
Definition collision.c:1480
static qbool collision_cachedtrace_rebuildhash
Definition collision.c:1478
cvar_t collision_cache
Definition collision.c:18
static unsigned char collision_cachedtrace_sequence
Definition collision.c:1471
int integer
Definition cvar.h:73

References collision_cache, Collision_Cache_RebuildHash(), Collision_Cache_Reset(), collision_cachedtrace_max, collision_cachedtrace_rebuildhash, collision_cachedtrace_sequence, and cvar_t::integer.

Referenced by CL_Frame().

◆ Collision_Cache_Reset()

void Collision_Cache_Reset ( qbool resetlimits)

Definition at line 1480 of file collision.c.

1481{
1494 if (resetlimits || !collision_cachedtrace_max)
1507}
static unsigned char * collision_cachedtrace_arrayused
Definition collision.c:1477
static unsigned int * collision_cachedtrace_arrayfullhashindex
Definition collision.c:1474
static mempool_t * collision_cachedtrace_mempool
Definition collision.c:1466
static int collision_cachedtrace_lastused
Definition collision.c:1469
static unsigned int * collision_cachedtrace_arrayhashindex
Definition collision.c:1475
static int collision_cachedtrace_firstfree
Definition collision.c:1468
static collision_cachedtrace_t * collision_cachedtrace_array
Definition collision.c:1467
static unsigned int * collision_cachedtrace_arraynext
Definition collision.c:1476
static int * collision_cachedtrace_hash
Definition collision.c:1473
static int collision_cachedtrace_hashsize
Definition collision.c:1472
#define Mem_Free(mem)
Definition zone.h:96
#define Mem_Alloc(pool, size)
Definition zone.h:92

References collision_cache, collision_cachedtrace_array, collision_cachedtrace_arrayfullhashindex, collision_cachedtrace_arrayhashindex, collision_cachedtrace_arraynext, collision_cachedtrace_arrayused, collision_cachedtrace_firstfree, collision_cachedtrace_hash, collision_cachedtrace_hashsize, collision_cachedtrace_lastused, collision_cachedtrace_max, collision_cachedtrace_mempool, collision_cachedtrace_rebuildhash, collision_cachedtrace_sequence, cvar_t::integer, Mem_Alloc, and Mem_Free.

Referenced by CL_ParseServerInfo(), Collision_Cache_Init(), Collision_Cache_Lookup(), Collision_Cache_NewFrame(), gl_main_start(), and SV_SpawnServer().

◆ Collision_CalcPlanesForTriangleBrushFloat()

void Collision_CalcPlanesForTriangleBrushFloat ( colbrushf_t * brush)

Definition at line 451 of file collision.c.

452{
453 float edge0[3], edge1[3], edge2[3];
454 colpointf_t *p;
455
456 TriangleNormal(brush->points[0].v, brush->points[1].v, brush->points[2].v, brush->planes[0].normal);
457 if (DotProduct(brush->planes[0].normal, brush->planes[0].normal) < 0.0001f)
458 {
459 // there's no point in processing a degenerate triangle (GIGO - Garbage In, Garbage Out)
460 // note that some of these exist in q3bsp bspline patches
461 brush->numplanes = 0;
462 return;
463 }
464
465 // there are 5 planes (front, back, sides) and 3 edges
466 brush->numplanes = 5;
467 brush->numedgedirs = 3;
468 VectorNormalize(brush->planes[0].normal);
469 brush->planes[0].dist = DotProduct(brush->points->v, brush->planes[0].normal);
470 VectorNegate(brush->planes[0].normal, brush->planes[1].normal);
471 brush->planes[1].dist = -brush->planes[0].dist;
472 // edge directions are easy to calculate
473 VectorSubtract(brush->points[2].v, brush->points[0].v, edge0);
474 VectorSubtract(brush->points[0].v, brush->points[1].v, edge1);
475 VectorSubtract(brush->points[1].v, brush->points[2].v, edge2);
476 VectorCopy(edge0, brush->edgedirs[0].v);
477 VectorCopy(edge1, brush->edgedirs[1].v);
478 VectorCopy(edge2, brush->edgedirs[2].v);
479 // now select an algorithm to generate the side planes
481 {
482 // use 45 degree slopes at the edges of the triangle to make a sinking trace error turn into "riding up" the slope rather than getting stuck
483 CrossProduct(edge0, brush->planes->normal, brush->planes[2].normal);
484 CrossProduct(edge1, brush->planes->normal, brush->planes[3].normal);
485 CrossProduct(edge2, brush->planes->normal, brush->planes[4].normal);
486 VectorNormalize(brush->planes[2].normal);
487 VectorNormalize(brush->planes[3].normal);
488 VectorNormalize(brush->planes[4].normal);
489 VectorAdd(brush->planes[2].normal, brush->planes[0].normal, brush->planes[2].normal);
490 VectorAdd(brush->planes[3].normal, brush->planes[0].normal, brush->planes[3].normal);
491 VectorAdd(brush->planes[4].normal, brush->planes[0].normal, brush->planes[4].normal);
492 VectorNormalize(brush->planes[2].normal);
493 VectorNormalize(brush->planes[3].normal);
494 VectorNormalize(brush->planes[4].normal);
495 }
497 {
498 float projectionnormal[3], projectionedge0[3], projectionedge1[3], projectionedge2[3];
499 int i, best;
500 float dist, bestdist;
501 bestdist = fabs(brush->planes[0].normal[0]);
502 best = 0;
503 for (i = 1;i < 3;i++)
504 {
505 dist = fabs(brush->planes[0].normal[i]);
506 if (bestdist < dist)
507 {
508 bestdist = dist;
509 best = i;
510 }
511 }
512 VectorClear(projectionnormal);
513 if (brush->planes[0].normal[best] < 0)
514 projectionnormal[best] = -1;
515 else
516 projectionnormal[best] = 1;
517 VectorCopy(edge0, projectionedge0);
518 VectorCopy(edge1, projectionedge1);
519 VectorCopy(edge2, projectionedge2);
520 projectionedge0[best] = 0;
521 projectionedge1[best] = 0;
522 projectionedge2[best] = 0;
523 CrossProduct(projectionedge0, projectionnormal, brush->planes[2].normal);
524 CrossProduct(projectionedge1, projectionnormal, brush->planes[3].normal);
525 CrossProduct(projectionedge2, projectionnormal, brush->planes[4].normal);
526 VectorNormalize(brush->planes[2].normal);
527 VectorNormalize(brush->planes[3].normal);
528 VectorNormalize(brush->planes[4].normal);
529 }
530 else
531 {
532 CrossProduct(edge0, brush->planes->normal, brush->planes[2].normal);
533 CrossProduct(edge1, brush->planes->normal, brush->planes[3].normal);
534 CrossProduct(edge2, brush->planes->normal, brush->planes[4].normal);
535 VectorNormalize(brush->planes[2].normal);
536 VectorNormalize(brush->planes[3].normal);
537 VectorNormalize(brush->planes[4].normal);
538 }
539 brush->planes[2].dist = DotProduct(brush->points[2].v, brush->planes[2].normal);
540 brush->planes[3].dist = DotProduct(brush->points[0].v, brush->planes[3].normal);
541 brush->planes[4].dist = DotProduct(brush->points[1].v, brush->planes[4].normal);
542
544 {
545 int i;
546 // validity check - will be disabled later
548 for (i = 0;i < brush->numplanes;i++)
549 {
550 int j;
551 for (j = 0, p = brush->points;j < brush->numpoints;j++, p++)
552 if (DotProduct(p->v, brush->planes[i].normal) > brush->planes[i].dist + COLLISION_PLANE_DIST_EPSILON)
553 Con_DPrintf("Error in brush plane generation, plane %i\n", i);
554 }
555 }
556}
cvar_t collision_triangle_bevelsides
Definition collision.c:19
static void Collision_ValidateBrush(colbrushf_t *brush)
Definition collision.c:65
cvar_t collision_triangle_axialsides
Definition collision.c:20
#define COLLISION_PLANE_DIST_EPSILON
Definition collision.c:11
void Con_DPrintf(const char *fmt,...)
A Con_Printf that only shows up if the "developer" cvar is set.
Definition console.c:1544
cvar_t developer_extra
Definition host.c:49
#define VectorNegate(a, b)
Definition mathlib.h:95
#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 TriangleNormal(a, b, c, n)
Definition mathlib.h:126
#define DotProduct(a, b)
Definition mathlib.h:98
#define VectorAdd(a, b, out)
Definition mathlib.h:100
float fabs(float f)

References COLLISION_PLANE_DIST_EPSILON, collision_triangle_axialsides, collision_triangle_bevelsides, Collision_ValidateBrush(), Con_DPrintf(), CrossProduct, developer_extra, colplanef_t::dist, DotProduct, colbrushf_t::edgedirs, fabs(), i, cvar_t::integer, colplanef_t::normal, colbrushf_t::numedgedirs, colbrushf_t::numplanes, colbrushf_t::planes, colbrushf_t::points, TriangleNormal, colpointf_t::v, VectorAdd, VectorClear, VectorCopy, VectorNegate, VectorNormalize, and VectorSubtract.

Referenced by Collision_TraceBrushTriangleFloat(), and Collision_TraceBrushTriangleMeshFloat().

◆ Collision_ClipLineToGenericEntity()

void Collision_ClipLineToGenericEntity ( trace_t * trace,
struct model_s * model,
const struct frameblend_s * frameblend,
const struct skeleton_s * skeleton,
const vec3_t bodymins,
const vec3_t bodymaxs,
int bodysupercontents,
matrix4x4_t * matrix,
matrix4x4_t * inversematrix,
const vec3_t start,
const vec3_t end,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask,
float extend,
qbool hitsurfaces )

◆ Collision_ClipLineToWorld()

void Collision_ClipLineToWorld ( trace_t * trace,
struct model_s * model,
const vec3_t start,
const vec3_t end,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask,
float extend,
qbool hitsurfaces )

◆ Collision_ClipPointToGenericEntity()

void Collision_ClipPointToGenericEntity ( trace_t * trace,
struct model_s * model,
const struct frameblend_s * frameblend,
const struct skeleton_s * skeleton,
const vec3_t bodymins,
const vec3_t bodymaxs,
int bodysupercontents,
matrix4x4_t * matrix,
matrix4x4_t * inversematrix,
const vec3_t start,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask )

◆ Collision_ClipPointToWorld()

void Collision_ClipPointToWorld ( trace_t * trace,
struct model_s * model,
const vec3_t start,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask )

◆ Collision_ClipToGenericEntity()

void Collision_ClipToGenericEntity ( trace_t * trace,
struct model_s * model,
const struct frameblend_s * frameblend,
const struct skeleton_s * skeleton,
const vec3_t bodymins,
const vec3_t bodymaxs,
int bodysupercontents,
matrix4x4_t * matrix,
matrix4x4_t * inversematrix,
const vec3_t start,
const vec3_t mins,
const vec3_t maxs,
const vec3_t end,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask,
float extend )

◆ Collision_ClipToWorld()

void Collision_ClipToWorld ( trace_t * trace,
struct model_s * model,
const vec3_t start,
const vec3_t mins,
const vec3_t maxs,
const vec3_t end,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask,
float extend )

◆ Collision_ClipTrace_Box()

void Collision_ClipTrace_Box ( trace_t * trace,
const vec3_t cmins,
const vec3_t cmaxs,
const vec3_t start,
const vec3_t mins,
const vec3_t maxs,
const vec3_t end,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask,
int boxsupercontents,
int boxq3surfaceflags,
const texture_t * boxtexture )

Definition at line 1053 of file model_brush.c.

1054{
1055#if 1
1056 colbrushf_t cbox;
1057 colplanef_t cbox_planes[6];
1058 cbox.isaabb = true;
1059 cbox.hasaabbplanes = true;
1060 cbox.supercontents = boxsupercontents;
1061 cbox.numplanes = 6;
1062 cbox.numpoints = 0;
1063 cbox.numtriangles = 0;
1064 cbox.planes = cbox_planes;
1065 cbox.points = NULL;
1066 cbox.elements = NULL;
1067 cbox.markframe = 0;
1068 cbox.mins[0] = 0;
1069 cbox.mins[1] = 0;
1070 cbox.mins[2] = 0;
1071 cbox.maxs[0] = 0;
1072 cbox.maxs[1] = 0;
1073 cbox.maxs[2] = 0;
1074 cbox_planes[0].normal[0] = 1;cbox_planes[0].normal[1] = 0;cbox_planes[0].normal[2] = 0;cbox_planes[0].dist = cmaxs[0] - mins[0];
1075 cbox_planes[1].normal[0] = -1;cbox_planes[1].normal[1] = 0;cbox_planes[1].normal[2] = 0;cbox_planes[1].dist = maxs[0] - cmins[0];
1076 cbox_planes[2].normal[0] = 0;cbox_planes[2].normal[1] = 1;cbox_planes[2].normal[2] = 0;cbox_planes[2].dist = cmaxs[1] - mins[1];
1077 cbox_planes[3].normal[0] = 0;cbox_planes[3].normal[1] = -1;cbox_planes[3].normal[2] = 0;cbox_planes[3].dist = maxs[1] - cmins[1];
1078 cbox_planes[4].normal[0] = 0;cbox_planes[4].normal[1] = 0;cbox_planes[4].normal[2] = 1;cbox_planes[4].dist = cmaxs[2] - mins[2];
1079 cbox_planes[5].normal[0] = 0;cbox_planes[5].normal[1] = 0;cbox_planes[5].normal[2] = -1;cbox_planes[5].dist = maxs[2] - cmins[2];
1080 cbox_planes[0].q3surfaceflags = boxq3surfaceflags;cbox_planes[0].texture = boxtexture;
1081 cbox_planes[1].q3surfaceflags = boxq3surfaceflags;cbox_planes[1].texture = boxtexture;
1082 cbox_planes[2].q3surfaceflags = boxq3surfaceflags;cbox_planes[2].texture = boxtexture;
1083 cbox_planes[3].q3surfaceflags = boxq3surfaceflags;cbox_planes[3].texture = boxtexture;
1084 cbox_planes[4].q3surfaceflags = boxq3surfaceflags;cbox_planes[4].texture = boxtexture;
1085 cbox_planes[5].q3surfaceflags = boxq3surfaceflags;cbox_planes[5].texture = boxtexture;
1086 memset(trace, 0, sizeof(trace_t));
1087 trace->hitsupercontentsmask = hitsupercontentsmask;
1088 trace->skipsupercontentsmask = skipsupercontentsmask;
1089 trace->skipmaterialflagsmask = skipmaterialflagsmask;
1090 trace->fraction = 1;
1091 Collision_TraceLineBrushFloat(trace, start, end, &cbox, &cbox);
1092#else
1094 static hull_t box_hull;
1095 static mclipnode_t box_clipnodes[6];
1096 static mplane_t box_planes[6];
1097 // fill in a default trace
1098 memset(&rhc, 0, sizeof(rhc));
1099 memset(trace, 0, sizeof(trace_t));
1100 //To keep everything totally uniform, bounding boxes are turned into small
1101 //BSP trees instead of being compared directly.
1102 // create a temp hull from bounding box sizes
1103 box_planes[0].dist = cmaxs[0] - mins[0];
1104 box_planes[1].dist = cmins[0] - maxs[0];
1105 box_planes[2].dist = cmaxs[1] - mins[1];
1106 box_planes[3].dist = cmins[1] - maxs[1];
1107 box_planes[4].dist = cmaxs[2] - mins[2];
1108 box_planes[5].dist = cmins[2] - maxs[2];
1109#if COLLISIONPARANOID >= 3
1110 Con_Printf("box_planes %f:%f %f:%f %f:%f\ncbox %f %f %f:%f %f %f\nbox %f %f %f:%f %f %f\n", box_planes[0].dist, box_planes[1].dist, box_planes[2].dist, box_planes[3].dist, box_planes[4].dist, box_planes[5].dist, cmins[0], cmins[1], cmins[2], cmaxs[0], cmaxs[1], cmaxs[2], mins[0], mins[1], mins[2], maxs[0], maxs[1], maxs[2]);
1111#endif
1112
1113 if (box_hull.clipnodes == NULL)
1114 {
1115 int i, side;
1116
1117 //Set up the planes and clipnodes so that the six floats of a bounding box
1118 //can just be stored out and get a proper hull_t structure.
1119
1120 box_hull.clipnodes = box_clipnodes;
1121 box_hull.planes = box_planes;
1122 box_hull.firstclipnode = 0;
1123 box_hull.lastclipnode = 5;
1124
1125 for (i = 0;i < 6;i++)
1126 {
1127 box_clipnodes[i].planenum = i;
1128
1129 side = i&1;
1130
1131 box_clipnodes[i].children[side] = CONTENTS_EMPTY;
1132 if (i != 5)
1133 box_clipnodes[i].children[side^1] = i + 1;
1134 else
1135 box_clipnodes[i].children[side^1] = CONTENTS_SOLID;
1136
1137 box_planes[i].type = i>>1;
1138 box_planes[i].normal[i>>1] = 1;
1139 }
1140 }
1141
1142 // trace a line through the generated clipping hull
1143 //rhc.boxsupercontents = boxsupercontents;
1144 rhc.hull = &box_hull;
1145 rhc.trace = trace;
1146 rhc.trace->hitsupercontentsmask = hitsupercontentsmask;
1147 rhc.trace->skipsupercontentsmask = skipsupercontentsmask;
1148 rhc.trace->skipmaterialflagsmask = skipmaterialflagsmask;
1149 rhc.trace->fraction = 1;
1150 rhc.trace->allsolid = true;
1151 VectorCopy(start, rhc.start);
1152 VectorCopy(end, rhc.end);
1153 VectorSubtract(rhc.end, rhc.start, rhc.dist);
1154 Mod_Q1BSP_RecursiveHullCheck(&rhc, rhc.hull->firstclipnode, 0, 1, rhc.start, rhc.end);
1155 //VectorMA(rhc.start, rhc.trace->fraction, rhc.dist, rhc.trace->endpos);
1156 if (rhc.trace->startsupercontents)
1157 rhc.trace->startsupercontents = boxsupercontents;
1158#endif
1159}
#define CONTENTS_SOLID
Definition bspfile.h:134
#define CONTENTS_EMPTY
Definition bspfile.h:133
void Collision_TraceLineBrushFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, const colbrushf_t *other_start, const colbrushf_t *other_end)
Definition collision.c:760
void Con_Printf(const char *fmt,...)
Prints to all appropriate console targets.
Definition console.c:1514
static int Mod_Q1BSP_RecursiveHullCheck(RecursiveHullCheckTraceInfo_t *t, int num, double p1f, double p2f, double p1[3], double p2[3])
#define NULL
Definition qtypes.h:12
int numtriangles
Definition collision.h:123
int * elements
Definition collision.h:124
mclipnode_t * clipnodes
int firstclipnode
int lastclipnode
mplane_t * planes
int children[2]
vec3_t normal
Definition model_brush.h:59
vec_t dist
Definition model_brush.h:60
int hitsupercontentsmask
Definition collision.h:50
double fraction
Definition collision.h:40
int startsupercontents
Definition collision.h:56
qbool allsolid
Definition collision.h:24
int skipsupercontentsmask
Definition collision.h:52
int skipmaterialflagsmask
Definition collision.h:54

References trace_t::allsolid, mclipnode_t::children, hull_t::clipnodes, Collision_TraceLineBrushFloat(), Con_Printf(), CONTENTS_EMPTY, CONTENTS_SOLID, colplanef_t::dist, mplane_t::dist, RecursiveHullCheckTraceInfo_t::dist, colbrushf_t::elements, RecursiveHullCheckTraceInfo_t::end, hull_t::firstclipnode, trace_t::fraction, colbrushf_t::hasaabbplanes, trace_t::hitsupercontentsmask, RecursiveHullCheckTraceInfo_t::hull, i, colbrushf_t::isaabb, hull_t::lastclipnode, colbrushf_t::markframe, colbrushf_t::maxs, maxs, colbrushf_t::mins, mins, Mod_Q1BSP_RecursiveHullCheck(), colplanef_t::normal, mplane_t::normal, NULL, colbrushf_t::numplanes, colbrushf_t::numpoints, colbrushf_t::numtriangles, mclipnode_t::planenum, colbrushf_t::planes, hull_t::planes, colbrushf_t::points, colplanef_t::q3surfaceflags, trace_t::skipmaterialflagsmask, trace_t::skipsupercontentsmask, RecursiveHullCheckTraceInfo_t::start, trace_t::startsupercontents, colbrushf_t::supercontents, colplanef_t::texture, RecursiveHullCheckTraceInfo_t::trace, mplane_t::type, VectorCopy, and VectorSubtract.

Referenced by CL_SelectTraceLine(), Collision_ClipLineToGenericEntity(), and Collision_ClipToGenericEntity().

◆ Collision_ClipTrace_Line_Sphere()

float Collision_ClipTrace_Line_Sphere ( double * linestart,
double * lineend,
double * sphereorigin,
double sphereradius,
double * impactpoint,
double * impactnormal )

Definition at line 1207 of file collision.c.

1208{
1209 double dir[3], scale, v[3], deviationdist2, impactdist, linelength;
1210 // make sure the impactpoint and impactnormal are valid even if there is
1211 // no collision
1212 VectorCopy(lineend, impactpoint);
1213 VectorClear(impactnormal);
1214 // calculate line direction
1215 VectorSubtract(lineend, linestart, dir);
1216 // normalize direction
1217 linelength = VectorLength(dir);
1218 if (linelength)
1219 {
1220 scale = 1.0 / linelength;
1222 }
1223 // this dotproduct calculates the distance along the line at which the
1224 // sphere origin is (nearest point to the sphere origin on the line)
1225 impactdist = DotProduct(sphereorigin, dir) - DotProduct(linestart, dir);
1226 // calculate point on line at that distance, and subtract the
1227 // sphereorigin from it, so we have a vector to measure for the distance
1228 // of the line from the sphereorigin (deviation, how off-center it is)
1229 VectorMA(linestart, impactdist, dir, v);
1230 VectorSubtract(v, sphereorigin, v);
1231 deviationdist2 = sphereradius * sphereradius - VectorLength2(v);
1232 // if squared offset length is outside the squared sphere radius, miss
1233 if (deviationdist2 < 0)
1234 return 1; // miss (off to the side)
1235 // nudge back to find the correct impact distance
1236 impactdist -= sqrt(deviationdist2);
1237 if (impactdist >= linelength)
1238 return 1; // miss (not close enough)
1239 if (impactdist < 0)
1240 return 1; // miss (linestart is past or inside sphere)
1241 // calculate new impactpoint
1242 VectorMA(linestart, impactdist, dir, impactpoint);
1243 // calculate impactnormal (surface normal at point of impact)
1244 VectorSubtract(impactpoint, sphereorigin, impactnormal);
1245 // normalize impactnormal
1246 VectorNormalize(impactnormal);
1247 // return fraction of movement distance
1248 return impactdist / linelength;
1249}
float scale
const GLdouble * v
Definition glquake.h:762
#define VectorLength(a)
Definition mathlib.h:109
#define VectorLength2(a)
Definition mathlib.h:110
#define VectorScale(in, scale, out)
Definition mathlib.h:111
#define VectorMA(a, scale, b, out)
Definition mathlib.h:114
float sqrt(float f)
vec2 dir

References dir, DotProduct, scale, sqrt(), v, VectorClear, VectorCopy, VectorLength, VectorLength2, VectorMA, VectorNormalize, VectorScale, and VectorSubtract.

◆ Collision_ClipTrace_Point()

void Collision_ClipTrace_Point ( trace_t * trace,
const vec3_t cmins,
const vec3_t cmaxs,
const vec3_t start,
int hitsupercontentsmask,
int skipsupercontentsmask,
int skipmaterialflagsmask,
int boxsupercontents,
int boxq3surfaceflags,
const texture_t * boxtexture )

Definition at line 1161 of file model_brush.c.

1162{
1163 memset(trace, 0, sizeof(trace_t));
1164 trace->fraction = 1;
1165 trace->hitsupercontentsmask = hitsupercontentsmask;
1166 trace->skipsupercontentsmask = skipsupercontentsmask;
1167 trace->skipmaterialflagsmask = skipmaterialflagsmask;
1168 if (BoxesOverlap(start, start, cmins, cmaxs))
1169 {
1170 trace->startsupercontents |= boxsupercontents;
1171 if ((hitsupercontentsmask & boxsupercontents) && !(skipsupercontentsmask & boxsupercontents))
1172 {
1173 trace->startsolid = true;
1174 trace->allsolid = true;
1175 }
1176 }
1177}
#define BoxesOverlap(a, b, c, d)
Definition mathlib.h:122
qbool startsolid
Definition collision.h:26

References trace_t::allsolid, BoxesOverlap, trace_t::fraction, trace_t::hitsupercontentsmask, trace_t::skipmaterialflagsmask, trace_t::skipsupercontentsmask, trace_t::startsolid, and trace_t::startsupercontents.

Referenced by Collision_ClipPointToGenericEntity().

◆ Collision_CombineTraces()

void Collision_CombineTraces ( trace_t * cliptrace,
const trace_t * trace,
void * touch,
qbool isbmodel )

Definition at line 1914 of file collision.c.

1915{
1916 // take the 'best' answers from the new trace and combine with existing data
1917 if (trace->allsolid)
1918 cliptrace->allsolid = true;
1919 if (trace->startsolid)
1920 {
1921 if (isbmodel)
1922 cliptrace->bmodelstartsolid = true;
1923 cliptrace->startsolid = true;
1924 if (cliptrace->fraction == 1)
1925 cliptrace->ent = touch;
1926 if (cliptrace->startdepth > trace->startdepth)
1927 {
1928 cliptrace->startdepth = trace->startdepth;
1929 VectorCopy(trace->startdepthnormal, cliptrace->startdepthnormal);
1930 }
1931 }
1932 // don't set this except on the world, because it can easily confuse
1933 // monsters underwater if there's a bmodel involved in the trace
1934 // (inopen && inwater is how they check water visibility)
1935 //if (trace->inopen)
1936 // cliptrace->inopen = true;
1937 if (trace->inwater)
1938 cliptrace->inwater = true;
1939 if ((trace->fraction < cliptrace->fraction) && (VectorLength2(trace->plane.normal) > 0))
1940 {
1941 cliptrace->fraction = trace->fraction;
1942 VectorCopy(trace->endpos, cliptrace->endpos);
1943 cliptrace->plane = trace->plane;
1944 cliptrace->ent = touch;
1945 cliptrace->hitsupercontents = trace->hitsupercontents;
1946 cliptrace->hitq3surfaceflags = trace->hitq3surfaceflags;
1947 cliptrace->hittexture = trace->hittexture;
1948 }
1949 cliptrace->startsupercontents |= trace->startsupercontents;
1950}
void * ent
Definition collision.h:47
const struct texture_s * hittexture
Definition collision.h:62
qbool bmodelstartsolid
Definition collision.h:30
double startdepthnormal[3]
Definition collision.h:69
int hitq3surfaceflags
Definition collision.h:60
double endpos[3]
Definition collision.h:42
plane_t plane
Definition collision.h:44
int hitsupercontents
Definition collision.h:58
qbool inwater
Definition collision.h:36
double startdepth
Definition collision.h:68
vec3_t normal
Definition collision.h:13

References trace_t::allsolid, trace_t::bmodelstartsolid, trace_t::endpos, trace_t::ent, trace_t::fraction, trace_t::hitq3surfaceflags, trace_t::hitsupercontents, trace_t::hittexture, trace_t::inwater, plane_t::normal, trace_t::plane, trace_t::startdepth, trace_t::startdepthnormal, trace_t::startsolid, trace_t::startsupercontents, VectorCopy, and VectorLength2.

Referenced by CL_Cache_TraceLineSurfaces(), CL_TraceBox(), CL_TraceLine(), CL_TracePoint(), SV_TraceBox(), SV_TraceLine(), and SV_TracePoint().

◆ Collision_Init()

void Collision_Init ( void )

Definition at line 25 of file collision.c.

26{
36 collision_mempool = Mem_AllocPool("collision cache", 0, NULL);
38}
cvar_t collision_bih_fullrecursion
Definition collision.c:21
void Collision_Cache_Init(mempool_t *mempool)
Definition collision.c:1509
mempool_t * collision_mempool
Definition collision.c:23
cvar_t collision_extendmovelength
Definition collision.c:14
cvar_t collision_debug_tracelineasbox
Definition collision.c:17
cvar_t collision_extendtracelinelength
Definition collision.c:16
cvar_t collision_impactnudge
Definition collision.c:13
cvar_t collision_extendtraceboxlength
Definition collision.c:15
void Cvar_RegisterVariable(cvar_t *variable)
registers a cvar that already has the name, string, and optionally the archive elements set.
Definition cvar.c:599
#define Mem_AllocPool(name, flags, parent)
Definition zone.h:104

References collision_bih_fullrecursion, collision_cache, Collision_Cache_Init(), collision_debug_tracelineasbox, collision_extendmovelength, collision_extendtraceboxlength, collision_extendtracelinelength, collision_impactnudge, collision_mempool, collision_triangle_axialsides, collision_triangle_bevelsides, Cvar_RegisterVariable(), Mem_AllocPool, and NULL.

Referenced by World_Init().

◆ Collision_NewBrushFromPlanes()

colbrushf_t * Collision_NewBrushFromPlanes ( struct mempool_s * mempool,
int numoriginalplanes,
const colplanef_t * originalplanes,
int supercontents,
int q3surfaceflags,
const texture_t * texture,
int hasaabbplanes )

◆ Collision_PointInsideBrushFloat()

qbool Collision_PointInsideBrushFloat ( const vec3_t point,
const colbrushf_t * brush )

Definition at line 910 of file collision.c.

911{
912 int nplane;
913 const colplanef_t *plane;
914
915 if (!BoxesOverlap(point, point, brush->mins, brush->maxs))
916 return false;
917 for (nplane = 0, plane = brush->planes;nplane < brush->numplanes;nplane++, plane++)
918 if (DotProduct(plane->normal, point) > plane->dist)
919 return false;
920 return true;
921}

References BoxesOverlap, colplanef_t::dist, DotProduct, colbrushf_t::maxs, colbrushf_t::mins, colplanef_t::normal, and colbrushf_t::planes.

◆ Collision_TraceBrushBrushFloat()

void Collision_TraceBrushBrushFloat ( trace_t * trace,
const colbrushf_t * thisbrush_start,
const colbrushf_t * thisbrush_end,
const colbrushf_t * thatbrush_start,
const colbrushf_t * thatbrush_end )

Definition at line 559 of file collision.c.

560{
561 int nplane, nplane2, nedge1, nedge2, hitq3surfaceflags = 0;
562 int tracenumedgedirs = trace_start->numedgedirs;
563 //int othernumedgedirs = other_start->numedgedirs;
564 int tracenumpoints = trace_start->numpoints;
565 int othernumpoints = other_start->numpoints;
566 int numplanes1 = other_start->numplanes;
567 int numplanes2 = numplanes1 + trace_start->numplanes;
568 int numplanes3 = numplanes2 + trace_start->numedgedirs * other_start->numedgedirs * 2;
569 vec_t enterfrac = -1, leavefrac = 1, startdist, enddist, ie, f, imove, enterfrac2 = -1;
570 vec4_t startplane;
571 vec4_t endplane;
572 vec4_t newimpactplane;
573 const texture_t *hittexture = NULL;
574 vec_t startdepth = 1;
575 vec3_t startdepthnormal;
576 const texture_t *starttexture = NULL;
577
578 VectorClear(startdepthnormal);
579 Vector4Clear(newimpactplane);
580
581 // fast case for AABB vs compiled brushes (which begin with AABB planes and also have precomputed bevels for AABB collisions)
582 if (trace_start->isaabb && other_start->hasaabbplanes)
583 numplanes3 = numplanes2 = numplanes1;
584
585 // Separating Axis Theorem:
586 // if a supporting vector (plane normal) can be found that separates two
587 // objects, they are not colliding.
588 //
589 // Minkowski Sum:
590 // reduce the size of one object to a point while enlarging the other to
591 // represent the space that point can not occupy.
592 //
593 // try every plane we can construct between the two brushes and measure
594 // the distance between them.
595 for (nplane = 0;nplane < numplanes3;nplane++)
596 {
597 if (nplane < numplanes1)
598 {
599 nplane2 = nplane;
600 VectorCopy(other_start->planes[nplane2].normal, startplane);
601 VectorCopy(other_end->planes[nplane2].normal, endplane);
602 }
603 else if (nplane < numplanes2)
604 {
605 nplane2 = nplane - numplanes1;
606 VectorCopy(trace_start->planes[nplane2].normal, startplane);
607 VectorCopy(trace_end->planes[nplane2].normal, endplane);
608 }
609 else
610 {
611 // pick an edgedir from each brush and cross them
612 nplane2 = nplane - numplanes2;
613 nedge1 = nplane2 >> 1;
614 nedge2 = nedge1 / tracenumedgedirs;
615 nedge1 -= nedge2 * tracenumedgedirs;
616 if (nplane2 & 1)
617 {
618 CrossProduct(trace_start->edgedirs[nedge1].v, other_start->edgedirs[nedge2].v, startplane);
619 CrossProduct(trace_end->edgedirs[nedge1].v, other_end->edgedirs[nedge2].v, endplane);
620 }
621 else
622 {
623 CrossProduct(other_start->edgedirs[nedge2].v, trace_start->edgedirs[nedge1].v, startplane);
624 CrossProduct(other_end->edgedirs[nedge2].v, trace_end->edgedirs[nedge1].v, endplane);
625 }
627 continue; // degenerate crossproducts
628 VectorNormalize(startplane);
629 VectorNormalize(endplane);
630 }
631 startplane[3] = furthestplanedist_float(startplane, other_start->points, othernumpoints);
632 endplane[3] = furthestplanedist_float(endplane, other_end->points, othernumpoints);
633 startdist = nearestplanedist_float(startplane, trace_start->points, tracenumpoints) - startplane[3];
634 enddist = nearestplanedist_float(endplane, trace_end->points, tracenumpoints) - endplane[3];
635 //Con_Printf("%c%i: startdist = %f, enddist = %f, startdist / (startdist - enddist) = %f\n", nplane2 != nplane ? 'b' : 'a', nplane2, startdist, enddist, startdist / (startdist - enddist));
636
637 // aside from collisions, this is also used for error correction
638 if (startdist <= 0.0f && nplane < numplanes1 && (startdepth < startdist || startdepth == 1))
639 {
640 startdepth = startdist;
641 VectorCopy(startplane, startdepthnormal);
642 starttexture = other_start->planes[nplane2].texture;
643 }
644
645 if (startdist > enddist)
646 {
647 // moving into brush
648 if (enddist > 0.0f)
649 return;
650 if (startdist >= 0)
651 {
652 // enter
653 imove = 1 / (startdist - enddist);
654 f = startdist * imove;
655 // check if this will reduce the collision time range
656 if (enterfrac < f)
657 {
658 // reduced collision time range
659 enterfrac = f;
660 // if the collision time range is now empty, no collision
661 if (enterfrac > leavefrac)
662 return;
663 // calculate the nudged fraction and impact normal we'll
664 // need if we accept this collision later
665 enterfrac2 = (startdist - collision_impactnudge.value) * imove;
666 // if the collision would be further away than the trace's
667 // existing collision data, we don't care about this
668 // collision
669 if (enterfrac2 >= trace->fraction)
670 return;
671 ie = 1.0f - enterfrac;
672 newimpactplane[0] = startplane[0] * ie + endplane[0] * enterfrac;
673 newimpactplane[1] = startplane[1] * ie + endplane[1] * enterfrac;
674 newimpactplane[2] = startplane[2] * ie + endplane[2] * enterfrac;
675 newimpactplane[3] = startplane[3] * ie + endplane[3] * enterfrac;
676 if (nplane < numplanes1)
677 {
678 // use the plane from other
679 nplane2 = nplane;
680 hitq3surfaceflags = other_start->planes[nplane2].q3surfaceflags;
681 hittexture = other_start->planes[nplane2].texture;
682 }
683 else if (nplane < numplanes2)
684 {
685 // use the plane from trace
686 nplane2 = nplane - numplanes1;
687 hitq3surfaceflags = trace_start->planes[nplane2].q3surfaceflags;
688 hittexture = trace_start->planes[nplane2].texture;
689 }
690 else
691 {
692 hitq3surfaceflags = other_start->q3surfaceflags;
693 hittexture = other_start->texture;
694 }
695 }
696 }
697 }
698 else
699 {
700 // moving out of brush
701 if (startdist >= 0)
702 return;
703 if (enddist > 0)
704 {
705 // leave
706 f = startdist / (startdist - enddist);
707 // check if this will reduce the collision time range
708 if (leavefrac > f)
709 {
710 // reduced collision time range
711 leavefrac = f;
712 // if the collision time range is now empty, no collision
713 if (enterfrac > leavefrac)
714 return;
715 }
716 }
717 }
718 }
719
720 // at this point we know the trace overlaps the brush because it was not
721 // rejected at any point in the loop above
722
723 // see if the trace started outside the brush or not
724 if (enterfrac > -1)
725 {
726 // started outside, and overlaps, therefore there is a collision here
727 // store out the impact information
728 if ((trace->hitsupercontentsmask & other_start->supercontents) && !(trace->skipsupercontentsmask & other_start->supercontents) && !(trace->skipmaterialflagsmask & (hittexture ? hittexture->currentmaterialflags : 0)))
729 {
730 trace->hitsupercontents = other_start->supercontents;
731 trace->hitq3surfaceflags = hitq3surfaceflags;
732 trace->hittexture = hittexture;
733 trace->fraction = bound(0, enterfrac2, 1);
734 VectorCopy(newimpactplane, trace->plane.normal);
735 trace->plane.dist = newimpactplane[3];
736 }
737 }
738 else
739 {
740 // started inside, update startsolid and friends
741 trace->startsupercontents |= other_start->supercontents;
742 if ((trace->hitsupercontentsmask & other_start->supercontents) && !(trace->skipsupercontentsmask & other_start->supercontents) && !(trace->skipmaterialflagsmask & (starttexture ? starttexture->currentmaterialflags : 0)))
743 {
744 trace->startsolid = true;
745 if (leavefrac < 1)
746 trace->allsolid = true;
747 VectorCopy(newimpactplane, trace->plane.normal);
748 trace->plane.dist = newimpactplane[3];
749 if (trace->startdepth > startdepth)
750 {
751 trace->startdepth = startdepth;
752 VectorCopy(startdepthnormal, trace->startdepthnormal);
753 trace->starttexture = starttexture;
754 }
755 }
756 }
757}
#define COLLISION_EDGECROSS_MINLENGTH2
Definition collision.c:7
static float nearestplanedist_float(const float *normal, const colpointf_t *points, int numpoints)
Definition collision.c:124
static float furthestplanedist_float(const float *normal, const colpointf_t *points, int numpoints)
Definition collision.c:140
#define bound(min, num, max)
Definition mathlib.h:34
#define Vector4Clear(a)
Definition mathlib.h:82
float vec_t
Definition qtypes.h:68
vec_t vec3_t[3]
Definition qtypes.h:71
vec_t vec4_t[4]
Definition qtypes.h:72
float f
float value
Definition cvar.h:74
int currentmaterialflags
const struct texture_s * starttexture
Definition collision.h:70
vec_t dist
Definition collision.h:14

References trace_t::allsolid, bound, COLLISION_EDGECROSS_MINLENGTH2, collision_impactnudge, CrossProduct, texture_t::currentmaterialflags, plane_t::dist, colbrushf_t::edgedirs, f, trace_t::fraction, furthestplanedist_float(), colbrushf_t::hasaabbplanes, trace_t::hitq3surfaceflags, trace_t::hitsupercontents, trace_t::hitsupercontentsmask, trace_t::hittexture, colbrushf_t::isaabb, nearestplanedist_float(), colplanef_t::normal, plane_t::normal, NULL, colbrushf_t::numedgedirs, colbrushf_t::numplanes, colbrushf_t::numpoints, trace_t::plane, colbrushf_t::planes, colbrushf_t::points, colbrushf_t::q3surfaceflags, colplanef_t::q3surfaceflags, trace_t::skipmaterialflagsmask, trace_t::skipsupercontentsmask, trace_t::startdepth, trace_t::startdepthnormal, trace_t::startsolid, trace_t::startsupercontents, trace_t::starttexture, colbrushf_t::supercontents, colbrushf_t::texture, colplanef_t::texture, colpointf_t::v, cvar_t::value, Vector4Clear, VectorClear, VectorCopy, VectorLength2, and VectorNormalize.

Referenced by Collision_TraceBrushTriangleFloat(), Collision_TraceBrushTriangleMeshFloat(), Collision_TraceLineBrushFloat(), and Mod_CollisionBIH_TraceBrush().

◆ Collision_TraceBrushTriangleFloat()

void Collision_TraceBrushTriangleFloat ( trace_t * trace,
const colbrushf_t * thisbrush_start,
const colbrushf_t * thisbrush_end,
const float * v0,
const float * v1,
const float * v2,
int supercontents,
int q3surfaceflags,
const texture_t * texture )

Definition at line 1107 of file collision.c.

1108{
1109 int i;
1110 colpointf_t points[3];
1111 colpointf_t edgedirs[3];
1112 colplanef_t planes[5];
1113 colbrushf_t brush;
1114 memset(&brush, 0, sizeof(brush));
1115 brush.isaabb = false;
1116 brush.hasaabbplanes = false;
1117 brush.numpoints = 3;
1118 brush.numedgedirs = 3;
1119 brush.numplanes = 5;
1120 brush.points = points;
1121 brush.edgedirs = edgedirs;
1122 brush.planes = planes;
1123 brush.supercontents = supercontents;
1124 brush.q3surfaceflags = q3surfaceflags;
1125 brush.texture = texture;
1126 for (i = 0;i < brush.numplanes;i++)
1127 {
1128 brush.planes[i].q3surfaceflags = q3surfaceflags;
1129 brush.planes[i].texture = texture;
1130 }
1131 VectorCopy(v0, points[0].v);
1132 VectorCopy(v1, points[1].v);
1133 VectorCopy(v2, points[2].v);
1137 //Collision_PrintBrushAsQHull(&brush, "brush");
1138 Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &brush, &brush);
1139}
#define COLLISION_SNAP
Definition collision.c:9
static void Collision_SnapCopyPoints(int numpoints, const colpointf_t *in, colpointf_t *out, float fractionprecision, float invfractionprecision)
Definition collision.c:985
static void Collision_CalcEdgeDirsForPolygonBrushFloat(colbrushf_t *brush)
Definition collision.c:156
void Collision_TraceBrushBrushFloat(trace_t *trace, const colbrushf_t *trace_start, const colbrushf_t *trace_end, const colbrushf_t *other_start, const colbrushf_t *other_end)
Definition collision.c:559
void Collision_CalcPlanesForTriangleBrushFloat(colbrushf_t *brush)
Definition collision.c:451
#define COLLISION_SNAPSCALE
Definition collision.c:8
GLfloat GLfloat GLfloat v2
Definition glquake.h:747
GLfloat v0
Definition glquake.h:739
GLfloat GLfloat v1
Definition glquake.h:743

References Collision_CalcEdgeDirsForPolygonBrushFloat(), Collision_CalcPlanesForTriangleBrushFloat(), COLLISION_SNAP, Collision_SnapCopyPoints(), COLLISION_SNAPSCALE, Collision_TraceBrushBrushFloat(), colbrushf_t::edgedirs, colbrushf_t::hasaabbplanes, i, colbrushf_t::isaabb, colbrushf_t::numedgedirs, colbrushf_t::numplanes, colbrushf_t::numpoints, colbrushf_t::planes, colbrushf_t::points, colbrushf_t::q3surfaceflags, colplanef_t::q3surfaceflags, colbrushf_t::supercontents, colbrushf_t::texture, colplanef_t::texture, texture, v, v0, v1, v2, and VectorCopy.

Referenced by Mod_CollisionBIH_TraceBrush().

◆ Collision_TraceBrushTriangleMeshFloat()

void Collision_TraceBrushTriangleMeshFloat ( trace_t * trace,
const colbrushf_t * thisbrush_start,
const colbrushf_t * thisbrush_end,
int numtriangles,
const int * element3i,
const float * vertex3f,
int stride,
float * bbox6f,
int supercontents,
int q3surfaceflags,
const texture_t * texture,
const vec3_t segmentmins,
const vec3_t segmentmaxs )

Definition at line 996 of file collision.c.

997{
998 int i;
999 colpointf_t points[3];
1000 colpointf_t edgedirs[3];
1001 colplanef_t planes[5];
1002 colbrushf_t brush;
1003 memset(&brush, 0, sizeof(brush));
1004 brush.isaabb = false;
1005 brush.hasaabbplanes = false;
1006 brush.numpoints = 3;
1007 brush.numedgedirs = 3;
1008 brush.numplanes = 5;
1009 brush.points = points;
1010 brush.edgedirs = edgedirs;
1011 brush.planes = planes;
1012 brush.supercontents = supercontents;
1013 brush.q3surfaceflags = q3surfaceflags;
1014 brush.texture = texture;
1015 for (i = 0;i < brush.numplanes;i++)
1016 {
1017 brush.planes[i].q3surfaceflags = q3surfaceflags;
1018 brush.planes[i].texture = texture;
1019 }
1020 if(stride > 0)
1021 {
1022 int k, cnt, tri;
1023 cnt = (numtriangles + stride - 1) / stride;
1024 for(i = 0; i < cnt; ++i)
1025 {
1026 if(BoxesOverlap(bbox6f + i * 6, bbox6f + i * 6 + 3, segmentmins, segmentmaxs))
1027 {
1028 for(k = 0; k < stride; ++k)
1029 {
1030 tri = i * stride + k;
1031 if(tri >= numtriangles)
1032 break;
1033 VectorCopy(vertex3f + element3i[tri * 3 + 0] * 3, points[0].v);
1034 VectorCopy(vertex3f + element3i[tri * 3 + 1] * 3, points[1].v);
1035 VectorCopy(vertex3f + element3i[tri * 3 + 2] * 3, points[2].v);
1039 //Collision_PrintBrushAsQHull(&brush, "brush");
1040 Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &brush, &brush);
1041 }
1042 }
1043 }
1044 }
1045 else if(stride == 0)
1046 {
1047 for (i = 0;i < numtriangles;i++, element3i += 3)
1048 {
1049 if (TriangleBBoxOverlapsBox(vertex3f + element3i[0]*3, vertex3f + element3i[1]*3, vertex3f + element3i[2]*3, segmentmins, segmentmaxs))
1050 {
1051 VectorCopy(vertex3f + element3i[0] * 3, points[0].v);
1052 VectorCopy(vertex3f + element3i[1] * 3, points[1].v);
1053 VectorCopy(vertex3f + element3i[2] * 3, points[2].v);
1057 //Collision_PrintBrushAsQHull(&brush, "brush");
1058 Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &brush, &brush);
1059 }
1060 }
1061 }
1062 else
1063 {
1064 for (i = 0;i < numtriangles;i++, element3i += 3)
1065 {
1066 VectorCopy(vertex3f + element3i[0] * 3, points[0].v);
1067 VectorCopy(vertex3f + element3i[1] * 3, points[1].v);
1068 VectorCopy(vertex3f + element3i[2] * 3, points[2].v);
1072 //Collision_PrintBrushAsQHull(&brush, "brush");
1073 Collision_TraceBrushBrushFloat(trace, thisbrush_start, thisbrush_end, &brush, &brush);
1074 }
1075 }
1076}
GLint GLenum GLboolean GLsizei stride
Definition glquake.h:797
#define TriangleBBoxOverlapsBox(a, b, c, d, e)
Definition mathlib.h:124

References BoxesOverlap, Collision_CalcEdgeDirsForPolygonBrushFloat(), Collision_CalcPlanesForTriangleBrushFloat(), COLLISION_SNAP, Collision_SnapCopyPoints(), COLLISION_SNAPSCALE, Collision_TraceBrushBrushFloat(), colbrushf_t::edgedirs, colbrushf_t::hasaabbplanes, i, colbrushf_t::isaabb, colbrushf_t::numedgedirs, colbrushf_t::numplanes, colbrushf_t::numpoints, colbrushf_t::planes, colbrushf_t::points, colbrushf_t::q3surfaceflags, colplanef_t::q3surfaceflags, stride, colbrushf_t::supercontents, colbrushf_t::texture, colplanef_t::texture, texture, TriangleBBoxOverlapsBox, v, and VectorCopy.

Referenced by Mod_MDLMD2MD3_TraceBox().

◆ Collision_TraceLineBrushFloat()

void Collision_TraceLineBrushFloat ( trace_t * trace,
const vec3_t linestart,
const vec3_t lineend,
const colbrushf_t * thatbrush_start,
const colbrushf_t * thatbrush_end )

Definition at line 760 of file collision.c.

761{
762 int nplane, hitq3surfaceflags = 0;
763 int numplanes = other_start->numplanes;
764 vec_t enterfrac = -1, leavefrac = 1, startdist, enddist, ie, f, imove, enterfrac2 = -1;
765 vec4_t startplane;
766 vec4_t endplane;
767 vec4_t newimpactplane;
768 const texture_t *hittexture = NULL;
769 vec_t startdepth = 1;
770 vec3_t startdepthnormal;
771 const texture_t *starttexture = NULL;
772
774 {
775 colboxbrushf_t thisbrush_start, thisbrush_end;
776 Collision_BrushForBox(&thisbrush_start, linestart, linestart, 0, 0, NULL);
777 Collision_BrushForBox(&thisbrush_end, lineend, lineend, 0, 0, NULL);
778 Collision_TraceBrushBrushFloat(trace, &thisbrush_start.brush, &thisbrush_end.brush, other_start, other_end);
779 return;
780 }
781
782 VectorClear(startdepthnormal);
783 Vector4Clear(newimpactplane);
784
785 // Separating Axis Theorem:
786 // if a supporting vector (plane normal) can be found that separates two
787 // objects, they are not colliding.
788 //
789 // Minkowski Sum:
790 // reduce the size of one object to a point while enlarging the other to
791 // represent the space that point can not occupy.
792 //
793 // try every plane we can construct between the two brushes and measure
794 // the distance between them.
795 for (nplane = 0;nplane < numplanes;nplane++)
796 {
797 VectorCopy(other_start->planes[nplane].normal, startplane);
798 startplane[3] = other_start->planes[nplane].dist;
799 VectorCopy(other_end->planes[nplane].normal, endplane);
800 endplane[3] = other_end->planes[nplane].dist;
801 startdist = DotProduct(linestart, startplane) - startplane[3];
802 enddist = DotProduct(lineend, endplane) - endplane[3];
803 //Con_Printf("%c%i: startdist = %f, enddist = %f, startdist / (startdist - enddist) = %f\n", nplane2 != nplane ? 'b' : 'a', nplane2, startdist, enddist, startdist / (startdist - enddist));
804
805 // aside from collisions, this is also used for error correction
806 if (startdist <= 0.0f && (startdepth < startdist || startdepth == 1))
807 {
808 startdepth = startdist;
809 VectorCopy(startplane, startdepthnormal);
810 starttexture = other_start->planes[nplane].texture;
811 }
812
813 if (startdist > enddist)
814 {
815 // moving into brush
816 if (enddist > 0.0f)
817 return;
818 if (startdist > 0)
819 {
820 // enter
821 imove = 1 / (startdist - enddist);
822 f = startdist * imove;
823 // check if this will reduce the collision time range
824 if (enterfrac < f)
825 {
826 // reduced collision time range
827 enterfrac = f;
828 // if the collision time range is now empty, no collision
829 if (enterfrac > leavefrac)
830 return;
831 // calculate the nudged fraction and impact normal we'll
832 // need if we accept this collision later
833 enterfrac2 = (startdist - collision_impactnudge.value) * imove;
834 // if the collision would be further away than the trace's
835 // existing collision data, we don't care about this
836 // collision
837 if (enterfrac2 >= trace->fraction)
838 return;
839 ie = 1.0f - enterfrac;
840 newimpactplane[0] = startplane[0] * ie + endplane[0] * enterfrac;
841 newimpactplane[1] = startplane[1] * ie + endplane[1] * enterfrac;
842 newimpactplane[2] = startplane[2] * ie + endplane[2] * enterfrac;
843 newimpactplane[3] = startplane[3] * ie + endplane[3] * enterfrac;
844 hitq3surfaceflags = other_start->planes[nplane].q3surfaceflags;
845 hittexture = other_start->planes[nplane].texture;
846 }
847 }
848 }
849 else
850 {
851 // moving out of brush
852 if (startdist > 0)
853 return;
854 if (enddist > 0)
855 {
856 // leave
857 f = startdist / (startdist - enddist);
858 // check if this will reduce the collision time range
859 if (leavefrac > f)
860 {
861 // reduced collision time range
862 leavefrac = f;
863 // if the collision time range is now empty, no collision
864 if (enterfrac > leavefrac)
865 return;
866 }
867 }
868 }
869 }
870
871 // at this point we know the trace overlaps the brush because it was not
872 // rejected at any point in the loop above
873
874 // see if the trace started outside the brush or not
875 if (enterfrac > -1)
876 {
877 // started outside, and overlaps, therefore there is a collision here
878 // store out the impact information
879 if ((trace->hitsupercontentsmask & other_start->supercontents) && !(trace->skipsupercontentsmask & other_start->supercontents) && !(trace->skipmaterialflagsmask & (hittexture ? hittexture->currentmaterialflags : 0)))
880 {
881 trace->hitsupercontents = other_start->supercontents;
882 trace->hitq3surfaceflags = hitq3surfaceflags;
883 trace->hittexture = hittexture;
884 trace->fraction = bound(0, enterfrac2, 1);
885 VectorCopy(newimpactplane, trace->plane.normal);
886 trace->plane.dist = newimpactplane[3];
887 }
888 }
889 else
890 {
891 // started inside, update startsolid and friends
892 trace->startsupercontents |= other_start->supercontents;
893 if ((trace->hitsupercontentsmask & other_start->supercontents) && !(trace->skipsupercontentsmask & other_start->supercontents) && !(trace->skipmaterialflagsmask & (starttexture ? starttexture->currentmaterialflags : 0)))
894 {
895 trace->startsolid = true;
896 if (leavefrac < 1)
897 trace->allsolid = true;
898 VectorCopy(newimpactplane, trace->plane.normal);
899 trace->plane.dist = newimpactplane[3];
900 if (trace->startdepth > startdepth)
901 {
902 trace->startdepth = startdepth;
903 VectorCopy(startdepthnormal, trace->startdepthnormal);
904 trace->starttexture = starttexture;
905 }
906 }
907 }
908}
void Collision_BrushForBox(colboxbrushf_t *boxbrush, const vec3_t mins, const vec3_t maxs, int supercontents, int q3surfaceflags, const texture_t *texture)
Definition collision.c:1141

References trace_t::allsolid, bound, colboxbrushf_t::brush, Collision_BrushForBox(), collision_debug_tracelineasbox, collision_impactnudge, Collision_TraceBrushBrushFloat(), texture_t::currentmaterialflags, colplanef_t::dist, plane_t::dist, DotProduct, f, trace_t::fraction, trace_t::hitq3surfaceflags, trace_t::hitsupercontents, trace_t::hitsupercontentsmask, trace_t::hittexture, cvar_t::integer, colplanef_t::normal, plane_t::normal, NULL, colbrushf_t::numplanes, trace_t::plane, colbrushf_t::planes, colplanef_t::q3surfaceflags, trace_t::skipmaterialflagsmask, trace_t::skipsupercontentsmask, trace_t::startdepth, trace_t::startdepthnormal, trace_t::startsolid, trace_t::startsupercontents, trace_t::starttexture, colbrushf_t::supercontents, colplanef_t::texture, cvar_t::value, Vector4Clear, VectorClear, and VectorCopy.

Referenced by Collision_ClipTrace_Box(), and Mod_CollisionBIH_TraceLineShared().

◆ Collision_TraceLineTriangleFloat()

void Collision_TraceLineTriangleFloat ( trace_t * trace,
const vec3_t linestart,
const vec3_t lineend,
const float * point0,
const float * point1,
const float * point2,
int supercontents,
int q3surfaceflags,
const texture_t * texture )

Definition at line 1251 of file collision.c.

1252{
1253 float d1, d2, d, f, f2, impact[3], edgenormal[3], faceplanenormal[3], faceplanedist, faceplanenormallength2, edge01[3], edge21[3], edge02[3];
1254
1255 // this function executes:
1256 // 32 ops when line starts behind triangle
1257 // 38 ops when line ends infront of triangle
1258 // 43 ops when line fraction is already closer than this triangle
1259 // 72 ops when line is outside edge 01
1260 // 92 ops when line is outside edge 21
1261 // 115 ops when line is outside edge 02
1262 // 123 ops when line impacts triangle and updates trace results
1263
1264 // this code is designed for clockwise triangles, conversion to
1265 // counterclockwise would require swapping some things around...
1266 // it is easier to simply swap the point0 and point2 parameters to this
1267 // function when calling it than it is to rewire the internals.
1268
1269 // calculate the faceplanenormal of the triangle, this represents the front side
1270 // 15 ops
1271 VectorSubtract(point0, point1, edge01);
1272 VectorSubtract(point2, point1, edge21);
1273 CrossProduct(edge01, edge21, faceplanenormal);
1274 // there's no point in processing a degenerate triangle (GIGO - Garbage In, Garbage Out)
1275 // 6 ops
1276 faceplanenormallength2 = DotProduct(faceplanenormal, faceplanenormal);
1277 if (faceplanenormallength2 < 0.0001f)
1278 return;
1279 // calculate the distance
1280 // 5 ops
1281 faceplanedist = DotProduct(point0, faceplanenormal);
1282
1283 // if start point is on the back side there is no collision
1284 // (we don't care about traces going through the triangle the wrong way)
1285
1286 // calculate the start distance
1287 // 6 ops
1288 d1 = DotProduct(faceplanenormal, linestart);
1289 if (d1 <= faceplanedist)
1290 return;
1291
1292 // calculate the end distance
1293 // 6 ops
1294 d2 = DotProduct(faceplanenormal, lineend);
1295 // if both are in front, there is no collision
1296 if (d2 >= faceplanedist)
1297 return;
1298
1299 // from here on we know d1 is >= 0 and d2 is < 0
1300 // this means the line starts infront and ends behind, passing through it
1301
1302 // calculate the recipricol of the distance delta,
1303 // so we can use it multiple times cheaply (instead of division)
1304 // 2 ops
1305 d = 1.0f / (d1 - d2);
1306 // calculate the impact fraction by taking the start distance (> 0)
1307 // and subtracting the face plane distance (this is the distance of the
1308 // triangle along that same normal)
1309 // then multiply by the recipricol distance delta
1310 // 4 ops
1311 f = (d1 - faceplanedist) * d;
1312 f2 = f - collision_impactnudge.value * d;
1313 // skip out if this impact is further away than previous ones
1314 // 1 ops
1315 if (f2 >= trace->fraction)
1316 return;
1317 // calculate the perfect impact point for classification of insidedness
1318 // 9 ops
1319 impact[0] = linestart[0] + f * (lineend[0] - linestart[0]);
1320 impact[1] = linestart[1] + f * (lineend[1] - linestart[1]);
1321 impact[2] = linestart[2] + f * (lineend[2] - linestart[2]);
1322
1323 // calculate the edge normal and reject if impact is outside triangle
1324 // (an edge normal faces away from the triangle, to get the desired normal
1325 // a crossproduct with the faceplanenormal is used, and because of the way
1326 // the insidedness comparison is written it does not need to be normalized)
1327
1328 // first use the two edges from the triangle plane math
1329 // the other edge only gets calculated if the point survives that long
1330
1331 // 20 ops
1332 CrossProduct(edge01, faceplanenormal, edgenormal);
1333 if (DotProduct(impact, edgenormal) > DotProduct(point1, edgenormal))
1334 return;
1335
1336 // 20 ops
1337 CrossProduct(faceplanenormal, edge21, edgenormal);
1338 if (DotProduct(impact, edgenormal) > DotProduct(point2, edgenormal))
1339 return;
1340
1341 // 23 ops
1342 VectorSubtract(point0, point2, edge02);
1343 CrossProduct(faceplanenormal, edge02, edgenormal);
1344 if (DotProduct(impact, edgenormal) > DotProduct(point0, edgenormal))
1345 return;
1346
1347 // 8 ops (rare)
1348
1349 // skip if this trace should not be blocked by these contents
1350 if (!(supercontents & trace->hitsupercontentsmask) || (supercontents & trace->skipsupercontentsmask) || (texture->currentmaterialflags & trace->skipmaterialflagsmask))
1351 return;
1352
1353 // store the new trace fraction
1354 trace->fraction = f2;
1355
1356 // store the new trace plane (because collisions only happen from
1357 // the front this is always simply the triangle normal, never flipped)
1358 d = 1.0 / sqrt(faceplanenormallength2);
1359 VectorScale(faceplanenormal, d, trace->plane.normal);
1360 trace->plane.dist = faceplanedist * d;
1361
1362 trace->hitsupercontents = supercontents;
1363 trace->hitq3surfaceflags = q3surfaceflags;
1364 trace->hittexture = texture;
1365}

References collision_impactnudge, CrossProduct, plane_t::dist, DotProduct, f, trace_t::fraction, trace_t::hitq3surfaceflags, trace_t::hitsupercontents, trace_t::hitsupercontentsmask, trace_t::hittexture, plane_t::normal, trace_t::plane, trace_t::skipmaterialflagsmask, trace_t::skipsupercontentsmask, sqrt(), texture, cvar_t::value, VectorScale, and VectorSubtract.

Referenced by Collision_TraceLineTriangleMeshFloat(), and Mod_CollisionBIH_TraceLineShared().

◆ Collision_TraceLineTriangleMeshFloat()

void Collision_TraceLineTriangleMeshFloat ( trace_t * trace,
const vec3_t linestart,
const vec3_t lineend,
int numtriangles,
const int * element3i,
const float * vertex3f,
int stride,
float * bbox6f,
int supercontents,
int q3surfaceflags,
const texture_t * texture,
const vec3_t segmentmins,
const vec3_t segmentmaxs )

Definition at line 1078 of file collision.c.

1079{
1080 int i;
1081 // FIXME: snap vertices?
1082 if(stride > 0)
1083 {
1084 int k, cnt, tri;
1085 cnt = (numtriangles + stride - 1) / stride;
1086 for(i = 0; i < cnt; ++i)
1087 {
1088 if(BoxesOverlap(bbox6f + i * 6, bbox6f + i * 6 + 3, segmentmins, segmentmaxs))
1089 {
1090 for(k = 0; k < stride; ++k)
1091 {
1092 tri = i * stride + k;
1093 if(tri >= numtriangles)
1094 break;
1095 Collision_TraceLineTriangleFloat(trace, linestart, lineend, vertex3f + element3i[tri * 3 + 0] * 3, vertex3f + element3i[tri * 3 + 1] * 3, vertex3f + element3i[tri * 3 + 2] * 3, supercontents, q3surfaceflags, texture);
1096 }
1097 }
1098 }
1099 }
1100 else
1101 {
1102 for (i = 0;i < numtriangles;i++, element3i += 3)
1103 Collision_TraceLineTriangleFloat(trace, linestart, lineend, vertex3f + element3i[0] * 3, vertex3f + element3i[1] * 3, vertex3f + element3i[2] * 3, supercontents, q3surfaceflags, texture);
1104 }
1105}
void Collision_TraceLineTriangleFloat(trace_t *trace, const vec3_t linestart, const vec3_t lineend, const float *point0, const float *point1, const float *point2, int supercontents, int q3surfaceflags, const texture_t *texture)
Definition collision.c:1251

References BoxesOverlap, Collision_TraceLineTriangleFloat(), i, stride, and texture.

Referenced by Mod_MDLMD2MD3_TraceLine().

◆ Collision_TracePointBrushFloat()

void Collision_TracePointBrushFloat ( trace_t * trace,
const vec3_t point,
const colbrushf_t * thatbrush )

Definition at line 923 of file collision.c.

924{
925 int nplane;
926 int numplanes = other_start->numplanes;
927 vec_t startdist;
928 vec4_t startplane;
929 vec4_t newimpactplane;
930 vec_t startdepth = 1;
931 vec3_t startdepthnormal;
932 const texture_t *starttexture = NULL;
933
934 VectorClear(startdepthnormal);
935 Vector4Clear(newimpactplane);
936
937 // Separating Axis Theorem:
938 // if a supporting vector (plane normal) can be found that separates two
939 // objects, they are not colliding.
940 //
941 // Minkowski Sum:
942 // reduce the size of one object to a point while enlarging the other to
943 // represent the space that point can not occupy.
944 //
945 // try every plane we can construct between the two brushes and measure
946 // the distance between them.
947 for (nplane = 0; nplane < numplanes; nplane++)
948 {
949 VectorCopy(other_start->planes[nplane].normal, startplane);
950 startplane[3] = other_start->planes[nplane].dist;
951 startdist = DotProduct(linestart, startplane) - startplane[3];
952
953 if (startdist > 0)
954 return;
955
956 // aside from collisions, this is also used for error correction
957 if (startdepth < startdist || startdepth == 1)
958 {
959 startdepth = startdist;
960 VectorCopy(startplane, startdepthnormal);
961 starttexture = other_start->planes[nplane].texture;
962 }
963 }
964
965 // at this point we know the trace overlaps the brush because it was not
966 // rejected at any point in the loop above
967
968 // started inside, update startsolid and friends
969 trace->startsupercontents |= other_start->supercontents;
970 if ((trace->hitsupercontentsmask & other_start->supercontents) && !(trace->skipsupercontentsmask & other_start->supercontents) && !(trace->skipmaterialflagsmask & (starttexture ? starttexture->currentmaterialflags : 0)))
971 {
972 trace->startsolid = true;
973 trace->allsolid = true;
974 VectorCopy(newimpactplane, trace->plane.normal);
975 trace->plane.dist = newimpactplane[3];
976 if (trace->startdepth > startdepth)
977 {
978 trace->startdepth = startdepth;
979 VectorCopy(startdepthnormal, trace->startdepthnormal);
980 trace->starttexture = starttexture;
981 }
982 }
983}

References trace_t::allsolid, texture_t::currentmaterialflags, colplanef_t::dist, plane_t::dist, DotProduct, trace_t::hitsupercontentsmask, colplanef_t::normal, plane_t::normal, NULL, colbrushf_t::numplanes, trace_t::plane, colbrushf_t::planes, trace_t::skipmaterialflagsmask, trace_t::skipsupercontentsmask, trace_t::startdepth, trace_t::startdepthnormal, trace_t::startsolid, trace_t::startsupercontents, trace_t::starttexture, colbrushf_t::supercontents, colplanef_t::texture, Vector4Clear, VectorClear, and VectorCopy.

Referenced by Mod_CollisionBIH_TracePoint().

Variable Documentation

◆ collision_bih_fullrecursion

struct cvar_s collision_bih_fullrecursion
extern

Definition at line 21 of file collision.c.

21{CF_CLIENT | CF_SERVER, "collision_bih_fullrecursion", "0", "debugging option to disable the bih recursion optimizations by iterating the entire tree"};
#define CF_SERVER
cvar/command that only the server can change/execute
Definition cmd.h:49
#define CF_CLIENT
cvar/command that only the client can change/execute
Definition cmd.h:48

Referenced by Collision_Init(), and Mod_CollisionBIH_TraceLineShared().

◆ collision_extendmovelength

◆ collision_extendtraceboxlength

struct cvar_s collision_extendtraceboxlength
extern

Definition at line 15 of file collision.c.

15{CF_CLIENT | CF_SERVER, "collision_extendtraceboxlength", "1", "internal bias for tracebox() qc builtin to account for collision_impactnudge (this does not alter the final trace length)"};

Referenced by Collision_Init(), VM_CL_tracebox(), and VM_SV_tracebox().

◆ collision_extendtracelinelength

struct cvar_s collision_extendtracelinelength
extern

Definition at line 16 of file collision.c.

16{CF_CLIENT | CF_SERVER, "collision_extendtracelinelength", "1", "internal bias for traceline() qc builtin to account for collision_impactnudge (this does not alter the final trace length)"};

Referenced by Collision_Init(), VM_CL_traceline(), and VM_SV_traceline().

◆ collision_impactnudge

struct cvar_s collision_impactnudge
extern