2 Copyright (C) 1996-1997 Id Software, Inc.
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License
6 as published by the Free Software Foundation; either version 2
7 of the License, or (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 See the GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 // world.c -- world query functions
26 entities never clip against themselves, or their owner
28 line of sight checks trace->crosscontent, but bullets don't
35 vec3_t boxmins, boxmaxs;// enclose the test object along entire move
36 float *mins, *maxs; // size of the moving object
37 vec3_t mins2, maxs2; // size when clipping against mosnters
46 ===============================================================================
50 ===============================================================================
54 static hull_t box_hull;
55 static dclipnode_t box_clipnodes[6];
56 static mplane_t box_planes[6];
62 Set up the planes and clipnodes so that the six floats of a bounding box
63 can just be stored out and get a proper hull_t structure.
66 void SV_InitBoxHull (void)
71 box_hull.clipnodes = box_clipnodes;
72 box_hull.planes = box_planes;
73 box_hull.firstclipnode = 0;
74 box_hull.lastclipnode = 5;
78 box_clipnodes[i].planenum = i;
82 box_clipnodes[i].children[side] = CONTENTS_EMPTY;
84 box_clipnodes[i].children[side^1] = i + 1;
86 box_clipnodes[i].children[side^1] = CONTENTS_SOLID;
88 box_planes[i].type = i>>1;
89 box_planes[i].normal[i>>1] = 1;
99 To keep everything totally uniform, bounding boxes are turned into small
100 BSP trees instead of being compared directly.
103 hull_t *SV_HullForBox (vec3_t mins, vec3_t maxs)
105 box_planes[0].dist = maxs[0];
106 box_planes[1].dist = mins[0];
107 box_planes[2].dist = maxs[1];
108 box_planes[3].dist = mins[1];
109 box_planes[4].dist = maxs[2];
110 box_planes[5].dist = mins[2];
121 Returns a hull that can be used for testing or clipping an object of mins/maxs
123 Offset is filled in to contain the adjustment that must be added to the
124 testing object's origin to get a point to use with the returned hull.
127 extern qboolean hlbsp;
128 hull_t *SV_HullForEntity (edict_t *ent, vec3_t mins, vec3_t maxs, vec3_t offset)
132 vec3_t hullmins, hullmaxs;
135 // decide which clipping hull to use, based on the size
136 if (ent->v.solid == SOLID_BSP)
137 { // explicit hulls in the BSP model
138 if (ent->v.movetype != MOVETYPE_PUSH)
139 Host_Error ("SOLID_BSP without MOVETYPE_PUSH");
141 model = sv.models[ (int)ent->v.modelindex ];
143 // LordHavoc: fixed SOLID_BSP error message
144 if (!model || model->type != mod_brush)
146 Con_Printf ("SOLID_BSP with a non bsp model, entity dump:\n");
148 Host_Error ("SOLID_BSP with a non bsp model\n");
151 VectorSubtract (maxs, mins, size);
152 // LordHavoc: FIXME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
156 hull = &model->hulls[0]; // 0x0x0
157 else if (size[0] <= 32)
159 if (size[2] < 54) // pick the nearest of 36 or 72
160 hull = &model->hulls[3]; // 32x32x36
162 hull = &model->hulls[1]; // 32x32x72
165 hull = &model->hulls[2]; // 64x64x64
170 hull = &model->hulls[0]; // 0x0x0
171 else if (size[0] <= 32)
172 hull = &model->hulls[1]; // 32x32x56
174 hull = &model->hulls[2]; // 64x64x88
177 // calculate an offset value to center the origin
178 VectorSubtract (hull->clip_mins, mins, offset);
179 VectorAdd (offset, ent->v.origin, offset);
182 { // create a temp hull from bounding box sizes
184 VectorSubtract (ent->v.mins, maxs, hullmins);
185 VectorSubtract (ent->v.maxs, mins, hullmaxs);
186 hull = SV_HullForBox (hullmins, hullmaxs);
188 VectorCopy (ent->v.origin, offset);
196 ===============================================================================
200 ===============================================================================
203 typedef struct areanode_s
205 int axis; // -1 = leaf node
207 struct areanode_s *children[2];
208 link_t trigger_edicts;
213 #define AREA_NODES 32
215 static areanode_t sv_areanodes[AREA_NODES];
216 static int sv_numareanodes;
224 areanode_t *SV_CreateAreaNode (int depth, vec3_t mins, vec3_t maxs)
228 vec3_t mins1, maxs1, mins2, maxs2;
230 anode = &sv_areanodes[sv_numareanodes];
233 ClearLink (&anode->trigger_edicts);
234 ClearLink (&anode->solid_edicts);
236 if (depth == AREA_DEPTH)
239 anode->children[0] = anode->children[1] = NULL;
243 VectorSubtract (maxs, mins, size);
244 if (size[0] > size[1])
249 anode->dist = 0.5 * (maxs[anode->axis] + mins[anode->axis]);
250 VectorCopy (mins, mins1);
251 VectorCopy (mins, mins2);
252 VectorCopy (maxs, maxs1);
253 VectorCopy (maxs, maxs2);
255 maxs1[anode->axis] = mins2[anode->axis] = anode->dist;
257 anode->children[0] = SV_CreateAreaNode (depth+1, mins2, maxs2);
258 anode->children[1] = SV_CreateAreaNode (depth+1, mins1, maxs1);
269 void SV_ClearWorld (void)
273 memset (sv_areanodes, 0, sizeof(sv_areanodes));
275 SV_CreateAreaNode (0, sv.worldmodel->mins, sv.worldmodel->maxs);
285 void SV_UnlinkEdict (edict_t *ent)
288 return; // not linked in anywhere
289 RemoveLink (&ent->area);
290 ent->area.prev = ent->area.next = NULL;
299 void SV_TouchLinks ( edict_t *ent, areanode_t *node )
303 int old_self, old_other;
306 // touch linked edicts
307 for (l = node->trigger_edicts.next ; l != &node->trigger_edicts ; l = next)
310 touch = EDICT_FROM_AREA(l);
313 if (!touch->v.touch || touch->v.solid != SOLID_TRIGGER)
315 if (ent->v.absmin[0] > touch->v.absmax[0]
316 || ent->v.absmin[1] > touch->v.absmax[1]
317 || ent->v.absmin[2] > touch->v.absmax[2]
318 || ent->v.absmax[0] < touch->v.absmin[0]
319 || ent->v.absmax[1] < touch->v.absmin[1]
320 || ent->v.absmax[2] < touch->v.absmin[2] )
322 old_self = pr_global_struct->self;
323 old_other = pr_global_struct->other;
325 pr_global_struct->self = EDICT_TO_PROG(touch);
326 pr_global_struct->other = EDICT_TO_PROG(ent);
327 pr_global_struct->time = sv.time;
328 PR_ExecuteProgram (touch->v.touch);
330 pr_global_struct->self = old_self;
331 pr_global_struct->other = old_other;
334 // recurse down both sides
335 if (node->axis == -1)
338 // LordHavoc: optimized recursion
339 // if (ent->v.absmax[node->axis] > node->dist) SV_TouchLinks (ent, node->children[0]);
340 // if (ent->v.absmin[node->axis] < node->dist) SV_TouchLinks (ent, node->children[1]);
341 if (ent->v.absmax[node->axis] > node->dist)
343 if (ent->v.absmin[node->axis] < node->dist)
344 SV_TouchLinks(ent, node->children[1]); // order reversed to reduce code
345 node = node->children[0];
350 if (ent->v.absmin[node->axis] < node->dist)
352 node = node->children[1];
365 void SV_FindTouchedLeafs (edict_t *ent, mnode_t *node)
367 mplane_t *splitplane;
373 if (node->contents == CONTENTS_SOLID)
376 // add an efrag if the node is a leaf
378 if ( node->contents < 0)
380 if (ent->num_leafs == MAX_ENT_LEAFS)
382 Con_DPrintf("FindTouchedLeafs overflow\n");
386 leaf = (mleaf_t *)node;
387 leafnum = leaf - sv.worldmodel->leafs - 1;
389 ent->leafnums[ent->num_leafs] = leafnum;
396 splitplane = node->plane;
397 sides = BOX_ON_PLANE_SIDE(ent->v.absmin, ent->v.absmax, splitplane);
399 // recurse down the contacted sides
400 // LordHavoc: optimized recursion
401 // if (sides & 1) SV_FindTouchedLeafs (ent, node->children[0]);
402 // if (sides & 2) SV_FindTouchedLeafs (ent, node->children[1]);
406 node = node->children[0];
409 node = node->children[1];
412 if (node->children[0]->contents != CONTENTS_SOLID)
413 SV_FindTouchedLeafs (ent, node->children[0]);
414 node = node->children[1];
425 void SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
430 SV_UnlinkEdict (ent); // unlink from old position
432 if (ent == sv.edicts)
433 return; // don't add the world
440 // LordHavoc: enabling rotating bmodels
441 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
442 { // expand for rotation
446 max = DotProduct(ent->v.mins, ent->v.mins);
447 v = DotProduct(ent->v.maxs, ent->v.maxs);
453 for (i=0 ; i<3 ; i++)
455 v = fabs(ent->v.mins[i]);
458 v = fabs(ent->v.maxs[i]);
463 for (i=0 ; i<3 ; i++)
465 ent->v.absmin[i] = ent->v.origin[i] - max;
466 ent->v.absmax[i] = ent->v.origin[i] + max;
471 VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
472 VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
476 // to make items easier to pick up and allow them to be grabbed off
477 // of shelves, the abs sizes are expanded
479 if ((int)ent->v.flags & FL_ITEM)
481 ent->v.absmin[0] -= 15;
482 ent->v.absmin[1] -= 15;
483 ent->v.absmax[0] += 15;
484 ent->v.absmax[1] += 15;
487 { // because movement is clipped an epsilon away from an actual edge,
488 // we must fully check even when bounding boxes don't quite touch
489 ent->v.absmin[0] -= 1;
490 ent->v.absmin[1] -= 1;
491 ent->v.absmin[2] -= 1;
492 ent->v.absmax[0] += 1;
493 ent->v.absmax[1] += 1;
494 ent->v.absmax[2] += 1;
499 if (ent->v.modelindex)
500 SV_FindTouchedLeafs (ent, sv.worldmodel->nodes);
502 if (ent->v.solid == SOLID_NOT)
505 // find the first node that the ent's box crosses
509 if (node->axis == -1)
511 if (ent->v.absmin[node->axis] > node->dist)
512 node = node->children[0];
513 else if (ent->v.absmax[node->axis] < node->dist)
514 node = node->children[1];
516 break; // crosses the node
521 if (ent->v.solid == SOLID_TRIGGER)
522 InsertLinkBefore (&ent->area, &node->trigger_edicts);
524 InsertLinkBefore (&ent->area, &node->solid_edicts);
526 // if touch_triggers, touch all entities at this node and descend for more
528 SV_TouchLinks ( ent, sv_areanodes );
534 ===============================================================================
536 POINT TESTING IN HULLS
538 ===============================================================================
541 // SV_HullPointContents moved to cpu_noasm.c
545 SV_TestEntityPosition
547 This could be a lot more efficient...
550 edict_t *SV_TestEntityPosition (edict_t *ent)
554 trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, ent->v.origin, 0, ent);
556 if (trace.startsolid)
564 ===============================================================================
566 LINE TESTING IN HULLS
568 ===============================================================================
571 // 1/32 epsilon to keep floating point happy
572 #define DIST_EPSILON (0.03125)
576 SV_RecursiveHullCheck
581 qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace)
596 if (num != CONTENTS_SOLID)
598 trace->allsolid = false;
599 if (num == CONTENTS_EMPTY)
600 trace->inopen = true;
602 trace->inwater = true;
605 trace->startsolid = true;
606 return true; // empty
609 if (num < hull->firstclipnode || num > hull->lastclipnode)
610 Sys_Error ("SV_RecursiveHullCheck: bad node number");
613 // find the point distances
615 node = hull->clipnodes + num;
616 plane = hull->planes + node->planenum;
618 t1 = PlaneDiff(p1, plane);
619 t2 = PlaneDiff(p2, plane);
622 if (t1 >= 0 && t2 >= 0)
623 // LordHavoc: optimized recursion
624 // return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
626 num = node->children[0];
629 if (t1 < 0 && t2 < 0)
630 // return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
632 num = node->children[1];
636 if ( (t1 >= DIST_EPSILON && t2 >= DIST_EPSILON) || (t2 > t1 && t1 >= 0) )
637 return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
638 if ( (t1 <= -DIST_EPSILON && t2 <= -DIST_EPSILON) || (t2 < t1 && t1 <= 0) )
639 return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
642 // put the crosspoint DIST_EPSILON pixels on the near side
644 frac = bound(0, (t1 + DIST_EPSILON)/(t1-t2), 1);
646 frac = bound(0, (t1 - DIST_EPSILON)/(t1-t2), 1);
648 midf = p1f + (p2f - p1f)*frac;
649 mid[0] = p1[0] + frac*(p2[0] - p1[0]);
650 mid[1] = p1[1] + frac*(p2[1] - p1[1]);
651 mid[2] = p1[2] + frac*(p2[2] - p1[2]);
655 // move up to the node
656 if (!SV_RecursiveHullCheck (hull, node->children[side], p1f, midf, p1, mid, trace) )
660 if (SV_HullPointContents (hull, node->children[side], mid) == CONTENTS_SOLID)
662 Con_Printf ("mid PointInHullSolid\n");
667 if (SV_HullPointContents (hull, node->children[side^1], mid) != CONTENTS_SOLID)
669 return SV_RecursiveHullCheck (hull, node->children[side^1], midf, p2f, mid, p2, trace);
670 // mid would need to be duplicated during recursion...
676 num = node->children[side^1];
683 return false; // never got out of the solid area
686 // the other side of the node is solid, this is the impact point
690 VectorCopy (plane->normal, trace->plane.normal);
691 trace->plane.dist = plane->dist;
695 // LordHavoc: unrolled vector operation because the compiler can't be sure vec3_origin is 0
696 // VectorSubtract (vec3_origin, plane->normal, trace->plane.normal);
697 trace->plane.normal[0] = -plane->normal[0];
698 trace->plane.normal[1] = -plane->normal[1];
699 trace->plane.normal[2] = -plane->normal[2];
700 trace->plane.dist = -plane->dist;
703 while (SV_HullPointContents (hull, hull->firstclipnode, mid) == CONTENTS_SOLID)
704 { // shouldn't really happen, but does occasionally
708 trace->fraction = midf;
709 VectorCopy (mid, trace->endpos);
710 Con_DPrintf ("backup past 0\n");
713 midf = p1f + (p2f - p1f)*frac;
714 for (i=0 ; i<3 ; i++)
715 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
718 trace->fraction = midf;
719 VectorCopy (mid, trace->endpos);
725 // LordHavoc: backported from my optimizations to PM_RecursiveHullCheck in QuakeForge newtree (QW)
726 qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace)
737 // LordHavoc: a goto! everyone flee in terror... :)
742 if (num != CONTENTS_SOLID)
744 trace->allsolid = false;
745 if (num == CONTENTS_EMPTY)
746 trace->inopen = true;
748 trace->inwater = true;
751 trace->startsolid = true;
752 return true; // empty
755 // LordHavoc: this can be eliminated by validating in the loader... but Mercury told me not to bother
756 if (num < hull->firstclipnode || num > hull->lastclipnode)
757 Sys_Error ("SV_RecursiveHullCheck: bad node number");
759 // find the point distances
760 node = hull->clipnodes + num;
761 plane = hull->planes + node->planenum;
765 t1 = p1[plane->type] - plane->dist;
766 t2 = p2[plane->type] - plane->dist;
770 t1 = DotProduct (plane->normal, p1) - plane->dist;
771 t2 = DotProduct (plane->normal, p2) - plane->dist;
774 // LordHavoc: recursion optimization
775 if (t1 >= 0 && t2 >= 0)
777 num = node->children[0];
780 if (t1 < 0 && t2 < 0)
782 num = node->children[1];
786 // put the crosspoint DIST_EPSILON pixels on the near side
789 frac = bound(0, (t1 + DIST_EPSILON) / (t1 - t2), 1);
791 frac = bound(0, (t1 - DIST_EPSILON) / (t1 - t2), 1);
793 midf = p1f + (p2f - p1f)*frac;
794 for (i=0 ; i<3 ; i++)
795 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
797 // move up to the node
798 if (!SV_RecursiveHullCheck (hull, node->children[side], p1f, midf, p1, mid, trace) )
802 if (SV_HullPointContents (pm_hullmodel, mid, node->children[side]) == CONTENTS_SOLID)
804 Con_Printf ("mid PointInHullSolid\n");
809 // LordHavoc: warning to the clumsy, this recursion can not be optimized because mid would need to be duplicated on a stack
810 if (SV_HullPointContents (hull, node->children[side^1], mid) != CONTENTS_SOLID)
812 return SV_RecursiveHullCheck (hull, node->children[side^1], midf, p2f, mid, p2, trace);
815 return false; // never got out of the solid area
818 // the other side of the node is solid, this is the impact point
822 VectorCopy (plane->normal, trace->plane.normal);
823 trace->plane.dist = plane->dist;
827 // LordHavoc: vec3_origin is evil; the compiler can not rely on it being '0 0 0'
828 // VectorSubtract (vec3_origin, plane->normal, trace->plane.normal);
829 trace->plane.normal[0] = -plane->normal[0];
830 trace->plane.normal[1] = -plane->normal[1];
831 trace->plane.normal[2] = -plane->normal[2];
832 trace->plane.dist = -plane->dist;
835 while (SV_HullPointContents (hull, hull->firstclipnode, mid) == CONTENTS_SOLID)
836 { // shouldn't really happen, but does occasionally
840 trace->fraction = midf;
841 VectorCopy (mid, trace->endpos);
842 Con_DPrintf ("backup past 0\n");
845 midf = p1f + (p2f - p1f)*frac;
846 for (i=0 ; i<3 ; i++)
847 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
850 trace->fraction = midf;
851 VectorCopy (mid, trace->endpos);
856 qboolean SV_TestLine (hull_t *hull, int num, vec3_t p1, vec3_t p2)
867 return num != CONTENTS_SOLID;
869 if (num < hull->firstclipnode || num > hull->lastclipnode)
870 Sys_Error ("SV_RecursiveHullCheck: bad node number");
873 // find the point distances
875 node = hull->clipnodes + num;
876 plane = hull->planes + node->planenum;
878 t1 = PlaneDiff(p1, plane);
879 t2 = PlaneDiff(p2, plane);
881 if (t1 >= 0 && t2 >= 0)
883 num = node->children[0];
886 if (t1 < 0 && t2 < 0)
888 num = node->children[1];
892 // put the crosspoint DIST_EPSILON pixels on the near side
896 frac = bound(0, (t1 + DIST_EPSILON)/(t1-t2), 1);
898 frac = bound(0, (t1 - DIST_EPSILON)/(t1-t2), 1);
900 mid[0] = p1[0] + frac*(p2[0] - p1[0]);
901 mid[1] = p1[1] + frac*(p2[1] - p1[1]);
902 mid[2] = p1[2] + frac*(p2[2] - p1[2]);
904 if (node->children[side] < 0)
906 if (node->children[side] == CONTENTS_SOLID)
908 return SV_TestLine(hull, node->children[!side], mid, p2);
910 else if (SV_TestLine(hull, node->children[side], p1, mid))
911 return SV_TestLine(hull, node->children[!side], mid, p2);
921 Handles selection or creation of a clipping hull, and offseting (and
922 eventually rotation) of the end points
925 trace_t SV_ClipMoveToEntity (edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
929 vec3_t start_l, end_l;
932 // fill in a default trace
933 memset (&trace, 0, sizeof(trace_t));
935 trace.allsolid = true;
936 VectorCopy (end, trace.endpos);
938 // get the clipping hull
939 hull = SV_HullForEntity (ent, mins, maxs, offset);
941 VectorSubtract (start, offset, start_l);
942 VectorSubtract (end, offset, end_l);
944 // LordHavoc: enabling rotating bmodels
945 // rotate start and end into the models frame of reference
946 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
948 vec3_t forward, right, up;
951 AngleVectors (ent->v.angles, forward, right, up);
953 VectorCopy (start_l, temp);
954 start_l[0] = DotProduct (temp, forward);
955 start_l[1] = -DotProduct (temp, right);
956 start_l[2] = DotProduct (temp, up);
958 VectorCopy (end_l, temp);
959 end_l[0] = DotProduct (temp, forward);
960 end_l[1] = -DotProduct (temp, right);
961 end_l[2] = DotProduct (temp, up);
964 // trace a line through the apropriate clipping hull
965 SV_RecursiveHullCheck (hull, hull->firstclipnode, 0, 1, start_l, end_l, &trace);
967 // LordHavoc: enabling rotating bmodels
968 // rotate endpos back to world frame of reference
969 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
972 vec3_t forward, right, up;
975 if (trace.fraction != 1)
977 VectorSubtract (vec3_origin, ent->v.angles, a);
978 AngleVectors (a, forward, right, up);
980 VectorCopy (trace.endpos, temp);
981 trace.endpos[0] = DotProduct (temp, forward);
982 trace.endpos[1] = -DotProduct (temp, right);
983 trace.endpos[2] = DotProduct (temp, up);
985 VectorCopy (trace.plane.normal, temp);
986 trace.plane.normal[0] = DotProduct (temp, forward);
987 trace.plane.normal[1] = -DotProduct (temp, right);
988 trace.plane.normal[2] = DotProduct (temp, up);
992 // fix trace up by the offset
993 if (trace.fraction != 1)
994 VectorAdd (trace.endpos, offset, trace.endpos);
996 // did we clip the move?
997 if (trace.fraction < 1 || trace.startsolid )
1003 //===========================================================================
1006 ====================
1009 Mins and maxs enclose the entire area swept by the move
1010 ====================
1012 void SV_ClipToLinks ( areanode_t *node, moveclip_t *clip )
1019 // touch linked edicts
1020 for (l = node->solid_edicts.next ; l != &node->solid_edicts ; l = next)
1023 touch = EDICT_FROM_AREA(l);
1024 if (touch->v.solid == SOLID_NOT)
1026 if (touch == clip->passedict)
1028 if (touch->v.solid == SOLID_TRIGGER)
1029 Sys_Error ("Trigger in clipping list");
1031 if (clip->type == MOVE_NOMONSTERS && touch->v.solid != SOLID_BSP)
1034 if (clip->boxmins[0] > touch->v.absmax[0]
1035 || clip->boxmins[1] > touch->v.absmax[1]
1036 || clip->boxmins[2] > touch->v.absmax[2]
1037 || clip->boxmaxs[0] < touch->v.absmin[0]
1038 || clip->boxmaxs[1] < touch->v.absmin[1]
1039 || clip->boxmaxs[2] < touch->v.absmin[2] )
1042 if (clip->passedict!=0 && clip->passedict->v.size[0] && !touch->v.size[0])
1043 continue; // points never interact
1045 // might intersect, so do an exact clip
1046 if (clip->trace.allsolid)
1048 if (clip->passedict)
1050 if (PROG_TO_EDICT(touch->v.owner) == clip->passedict)
1051 continue; // don't clip against own missiles
1052 if (PROG_TO_EDICT(clip->passedict->v.owner) == touch)
1053 continue; // don't clip against owner
1054 // LordHavoc: corpse code
1055 if (clip->passedict->v.solid == SOLID_CORPSE && touch->v.solid == SOLID_SLIDEBOX)
1057 if (clip->passedict->v.solid == SOLID_SLIDEBOX && touch->v.solid == SOLID_CORPSE)
1061 if ((int)touch->v.flags & FL_MONSTER)
1062 trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins2, clip->maxs2, clip->end);
1064 trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins, clip->maxs, clip->end);
1065 if (trace.allsolid || trace.startsolid ||
1066 trace.fraction < clip->trace.fraction)
1069 if (clip->trace.startsolid)
1071 clip->trace = trace;
1072 clip->trace.startsolid = true;
1075 clip->trace = trace;
1077 else if (trace.startsolid)
1078 clip->trace.startsolid = true;
1081 // recurse down both sides
1082 if (node->axis == -1)
1085 // LordHavoc: optimized recursion
1086 // if (clip->boxmaxs[node->axis] > node->dist) SV_ClipToLinks(node->children[0], clip);
1087 // if (clip->boxmins[node->axis] < node->dist) SV_ClipToLinks(node->children[1], clip);
1088 if (clip->boxmaxs[node->axis] > node->dist)
1090 if (clip->boxmins[node->axis] < node->dist)
1091 SV_ClipToLinks(node->children[1], clip);
1092 node = node->children[0];
1095 else if (clip->boxmins[node->axis] < node->dist)
1097 node = node->children[1];
1108 void SV_MoveBounds (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, vec3_t boxmins, vec3_t boxmaxs)
1111 // debug to test against everything
1112 boxmins[0] = boxmins[1] = boxmins[2] = -9999;
1113 boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 9999;
1117 for (i=0 ; i<3 ; i++)
1119 if (end[i] > start[i])
1121 boxmins[i] = start[i] + mins[i] - 1;
1122 boxmaxs[i] = end[i] + maxs[i] + 1;
1126 boxmins[i] = end[i] + mins[i] - 1;
1127 boxmaxs[i] = start[i] + maxs[i] + 1;
1138 trace_t SV_Move (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict)
1143 memset ( &clip, 0, sizeof ( moveclip_t ) );
1146 clip.trace = SV_ClipMoveToEntity ( sv.edicts, start, mins, maxs, end );
1153 clip.passedict = passedict;
1155 if (type == MOVE_MISSILE)
1157 for (i=0 ; i<3 ; i++)
1159 clip.mins2[i] = -15;
1165 VectorCopy (mins, clip.mins2);
1166 VectorCopy (maxs, clip.maxs2);
1169 // create the bounding box of the entire move
1170 SV_MoveBounds ( start, clip.mins2, clip.maxs2, end, clip.boxmins, clip.boxmaxs );
1173 SV_ClipToLinks ( sv_areanodes, &clip );