3 #include "cl_collision.h"
7 typedef struct physentity_s
9 // this may be a entity_t, or a edict_t, or whatever
12 // can be NULL if it is a bbox object
15 // node this entity crosses
16 // for avoiding unnecessary collisions
19 // matrix for converting from model to world coordinates
20 double modeltoworldmatrix[3][4];
22 // matrix for converting from world to model coordinates
23 double worldtomodelmatrix[3][4];
25 // if this is a bmodel, this is used for culling it quickly
26 // if this is not a bmodel, this is used for actual collisions
27 double mins[3], maxs[3];
32 int cl_traceline_startsupercontents;
34 float CL_TraceLine(const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int hitbmodels, entity_render_t **hitent, int hitsupercontentsmask)
36 float maxfrac, maxrealfrac;
39 float tracemins[3], tracemaxs[3];
41 matrix4x4_t matrix, imatrix;
42 float tempnormal[3], starttransformed[3], endtransformed[3];
45 *hitent = &cl_entities[0].render;
46 Mod_CheckLoaded(cl.worldmodel);
47 if (cl.worldmodel && cl.worldmodel->TraceBox)
48 cl.worldmodel->TraceBox(cl.worldmodel, 0, &trace, start, start, end, end, hitsupercontentsmask);
51 VectorCopy(trace.plane.normal, normal);
52 cl_traceline_startsupercontents = trace.startsupercontents;
53 maxfrac = trace.fraction;
54 maxrealfrac = trace.realfraction;
56 if (hitbmodels && cl_num_brushmodel_entities)
58 tracemins[0] = min(start[0], end[0]);
59 tracemaxs[0] = max(start[0], end[0]);
60 tracemins[1] = min(start[1], end[1]);
61 tracemaxs[1] = max(start[1], end[1]);
62 tracemins[2] = min(start[2], end[2]);
63 tracemaxs[2] = max(start[2], end[2]);
65 // look for embedded bmodels
66 for (n = 0;n < cl_num_brushmodel_entities;n++)
68 ent = cl_brushmodel_entities[n];
69 if (ent->mins[0] > tracemaxs[0] || ent->maxs[0] < tracemins[0]
70 || ent->mins[1] > tracemaxs[1] || ent->maxs[1] < tracemins[1]
71 || ent->mins[2] > tracemaxs[2] || ent->maxs[2] < tracemins[2])
74 Matrix4x4_CreateFromQuakeEntity(&matrix, ent->origin[0], ent->origin[1], ent->origin[2], ent->angles[0], ent->angles[1], ent->angles[2], 1);
75 Matrix4x4_Invert_Simple(&imatrix, &matrix);
76 Matrix4x4_Transform(&imatrix, start, starttransformed);
77 Matrix4x4_Transform(&imatrix, end, endtransformed);
79 if (ent->model && ent->model->TraceBox)
80 ent->model->TraceBox(ent->model, 0, &trace, starttransformed, starttransformed, endtransformed, endtransformed, hitsupercontentsmask);
82 cl_traceline_startsupercontents |= trace.startsupercontents;
83 if (maxrealfrac > trace.realfraction)
87 maxfrac = trace.fraction;
88 maxrealfrac = trace.realfraction;
91 VectorCopy(trace.plane.normal, tempnormal);
92 Matrix4x4_Transform3x3(&matrix, tempnormal, normal);
97 if (maxfrac < 0 || maxfrac > 1) Con_Printf("fraction out of bounds %f %s:%d\n", maxfrac, __FILE__, __LINE__);
99 VectorLerp(start, maxfrac, end, impact);
103 void CL_FindNonSolidLocation(const vec3_t in, vec3_t out, vec_t radius)
105 // FIXME: check multiple brush models
106 if (cl.worldmodel && cl.worldmodel->brush.FindNonSolidLocation)
107 cl.worldmodel->brush.FindNonSolidLocation(cl.worldmodel, in, out, radius);
110 int CL_PointQ1Contents(const vec3_t p)
112 CL_TraceLine(p, p, NULL, NULL, true, NULL, 0);
113 return Mod_Q1BSP_NativeContentsFromSuperContents(NULL, cl_traceline_startsupercontents);
115 // FIXME: check multiple brush models
116 if (cl.worldmodel && cl.worldmodel->brush.PointContentsQ1)
117 return cl.worldmodel->brush.PointContentsQ1(cl.worldmodel, p);
122 int CL_PointSuperContents(const vec3_t p)
124 CL_TraceLine(p, p, NULL, NULL, true, NULL, 0);
125 return cl_traceline_startsupercontents;
127 // FIXME: check multiple brush models
128 if (cl.worldmodel && cl.worldmodel->brush.PointContentsQ1)
129 return cl.worldmodel->brush.PointContentsQ1(cl.worldmodel, p);