]> icculus.org git repositories - divverent/darkplaces.git/blob - cl_collision.c
you can now open/close the console independently of menu and messagemode
[divverent/darkplaces.git] / cl_collision.c
1
2 #include "quakedef.h"
3
4 /*
5 // not yet used
6 typedef struct physentity_s
7 {
8         // this may be a entity_t, or a edict_t, or whatever
9         void *realentity;
10
11         // can be NULL if it is a bbox object
12         model_t *bmodel;
13
14         // node this entity crosses
15         // for avoiding unnecessary collisions
16         physnode_t *node;
17
18         // matrix for converting from model to world coordinates
19         double modeltoworldmatrix[3][4];
20
21         // matrix for converting from world to model coordinates
22         double worldtomodelmatrix[3][4];
23
24         // if this is a bmodel, this is used for culling it quickly
25         // if this is not a bmodel, this is used for actual collisions
26         double mins[3], maxs[3];
27 }
28 physentity_t;
29 */
30
31 int cl_traceline_endcontents;
32
33 float CL_TraceLine (const vec3_t start, const vec3_t end, vec3_t impact, vec3_t normal, int contents, int hitbmodels)
34 {
35         double maxfrac;
36         trace_t trace;
37
38         Mod_CheckLoaded(cl.worldmodel);
39         Collision_ClipTrace(&trace, NULL, cl.worldmodel, vec3_origin, vec3_origin, vec3_origin, vec3_origin, start, vec3_origin, vec3_origin, end);
40
41         if (impact)
42                 VectorCopy (trace.endpos, impact);
43         if (normal)
44                 VectorCopy (trace.plane.normal, normal);
45         cl_traceline_endcontents = trace.endcontents;
46         maxfrac = trace.fraction;
47
48         if (hitbmodels && cl_num_brushmodel_entities)
49         {
50                 int n;
51                 entity_render_t *ent;
52                 double tracemins[3], tracemaxs[3];
53                 tracemins[0] = min(start[0], end[0]);
54                 tracemaxs[0] = max(start[0], end[0]);
55                 tracemins[1] = min(start[1], end[1]);
56                 tracemaxs[1] = max(start[1], end[1]);
57                 tracemins[2] = min(start[2], end[2]);
58                 tracemaxs[2] = max(start[2], end[2]);
59
60                 // look for embedded bmodels
61                 for (n = 0;n < cl_num_brushmodel_entities;n++)
62                 {
63                         ent = cl_brushmodel_entities[n];
64                         if (ent->mins[0] > tracemaxs[0] || ent->maxs[0] < tracemins[0]
65                          || ent->mins[1] > tracemaxs[1] || ent->maxs[1] < tracemins[1]
66                          || ent->mins[2] > tracemaxs[2] || ent->maxs[2] < tracemins[2])
67                                 continue;
68
69                         Collision_ClipTrace(&trace, ent, ent->model, ent->origin, ent->angles, ent->mins, ent->maxs, start, vec3_origin, vec3_origin, end);
70
71                         if (trace.allsolid || trace.startsolid || trace.fraction < maxfrac)
72                         {
73                                 maxfrac = trace.fraction;
74                                 if (impact)
75                                         VectorCopy(trace.endpos, impact);
76                                 if (normal)
77                                         VectorCopy(trace.plane.normal, normal);
78                                 cl_traceline_endcontents = trace.endcontents;
79                         }
80                 }
81         }
82         return maxfrac;
83 }
84