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 hull_t *SV_HullForEntity (edict_t *ent, vec3_t mins, vec3_t maxs, vec3_t offset)
131 vec3_t hullmins, hullmaxs;
134 // decide which clipping hull to use, based on the size
135 if (ent->v.solid == SOLID_BSP)
136 { // explicit hulls in the BSP model
137 if (ent->v.movetype != MOVETYPE_PUSH)
138 Host_Error ("SOLID_BSP without MOVETYPE_PUSH");
140 model = sv.models[ (int)ent->v.modelindex ];
142 // LordHavoc: fixed SOLID_BSP error message
143 if (!model || model->type != mod_brush)
145 Con_Printf ("SOLID_BSP with a non bsp model, entity dump:\n");
147 Host_Error ("SOLID_BSP with a non bsp model\n");
150 VectorSubtract (maxs, mins, size);
151 // LordHavoc: FIXME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
155 hull = &model->hulls[0]; // 0x0x0
156 else if (size[0] <= 32)
158 if (size[2] < 54) // pick the nearest of 36 or 72
159 hull = &model->hulls[3]; // 32x32x36
161 hull = &model->hulls[1]; // 32x32x72
164 hull = &model->hulls[2]; // 64x64x64
169 hull = &model->hulls[0]; // 0x0x0
170 else if (size[0] <= 32)
171 hull = &model->hulls[1]; // 32x32x56
173 hull = &model->hulls[2]; // 64x64x88
176 // calculate an offset value to center the origin
177 VectorSubtract (hull->clip_mins, mins, offset);
178 VectorAdd (offset, ent->v.origin, offset);
181 { // create a temp hull from bounding box sizes
183 VectorSubtract (ent->v.mins, maxs, hullmins);
184 VectorSubtract (ent->v.maxs, mins, hullmaxs);
185 hull = SV_HullForBox (hullmins, hullmaxs);
187 VectorCopy (ent->v.origin, offset);
195 ===============================================================================
199 ===============================================================================
202 typedef struct areanode_s
204 int axis; // -1 = leaf node
206 struct areanode_s *children[2];
207 link_t trigger_edicts;
212 #define AREA_NODES 32
214 static areanode_t sv_areanodes[AREA_NODES];
215 static int sv_numareanodes;
223 areanode_t *SV_CreateAreaNode (int depth, vec3_t mins, vec3_t maxs)
227 vec3_t mins1, maxs1, mins2, maxs2;
229 anode = &sv_areanodes[sv_numareanodes];
232 ClearLink (&anode->trigger_edicts);
233 ClearLink (&anode->solid_edicts);
235 if (depth == AREA_DEPTH)
238 anode->children[0] = anode->children[1] = NULL;
242 VectorSubtract (maxs, mins, size);
243 if (size[0] > size[1])
248 anode->dist = 0.5 * (maxs[anode->axis] + mins[anode->axis]);
249 VectorCopy (mins, mins1);
250 VectorCopy (mins, mins2);
251 VectorCopy (maxs, maxs1);
252 VectorCopy (maxs, maxs2);
254 maxs1[anode->axis] = mins2[anode->axis] = anode->dist;
256 anode->children[0] = SV_CreateAreaNode (depth+1, mins2, maxs2);
257 anode->children[1] = SV_CreateAreaNode (depth+1, mins1, maxs1);
268 void SV_ClearWorld (void)
272 memset (sv_areanodes, 0, sizeof(sv_areanodes));
274 SV_CreateAreaNode (0, sv.worldmodel->mins, sv.worldmodel->maxs);
284 void SV_UnlinkEdict (edict_t *ent)
287 return; // not linked in anywhere
288 RemoveLink (&ent->area);
289 ent->area.prev = ent->area.next = NULL;
298 void SV_TouchLinks ( edict_t *ent, areanode_t *node )
302 int old_self, old_other;
305 // touch linked edicts
306 for (l = node->trigger_edicts.next ; l != &node->trigger_edicts ; l = next)
309 touch = EDICT_FROM_AREA(l);
312 if (!touch->v.touch || touch->v.solid != SOLID_TRIGGER)
314 if (ent->v.absmin[0] > touch->v.absmax[0]
315 || ent->v.absmin[1] > touch->v.absmax[1]
316 || ent->v.absmin[2] > touch->v.absmax[2]
317 || ent->v.absmax[0] < touch->v.absmin[0]
318 || ent->v.absmax[1] < touch->v.absmin[1]
319 || ent->v.absmax[2] < touch->v.absmin[2] )
321 old_self = pr_global_struct->self;
322 old_other = pr_global_struct->other;
324 pr_global_struct->self = EDICT_TO_PROG(touch);
325 pr_global_struct->other = EDICT_TO_PROG(ent);
326 pr_global_struct->time = sv.time;
327 PR_ExecuteProgram (touch->v.touch, "");
329 pr_global_struct->self = old_self;
330 pr_global_struct->other = old_other;
333 // recurse down both sides
334 if (node->axis == -1)
337 // LordHavoc: optimized recursion
338 // if (ent->v.absmax[node->axis] > node->dist) SV_TouchLinks (ent, node->children[0]);
339 // if (ent->v.absmin[node->axis] < node->dist) SV_TouchLinks (ent, node->children[1]);
340 if (ent->v.absmax[node->axis] > node->dist)
342 if (ent->v.absmin[node->axis] < node->dist)
343 SV_TouchLinks(ent, node->children[1]); // order reversed to reduce code
344 node = node->children[0];
349 if (ent->v.absmin[node->axis] < node->dist)
351 node = node->children[1];
364 void SV_FindTouchedLeafs (edict_t *ent, mnode_t *node)
366 mplane_t *splitplane;
372 if (node->contents == CONTENTS_SOLID)
375 // add an efrag if the node is a leaf
377 if ( node->contents < 0)
379 if (ent->num_leafs == MAX_ENT_LEAFS)
381 Con_DPrintf("FindTouchedLeafs overflow\n");
385 leaf = (mleaf_t *)node;
386 leafnum = leaf - sv.worldmodel->leafs - 1;
388 ent->leafnums[ent->num_leafs] = leafnum;
395 splitplane = node->plane;
396 sides = BOX_ON_PLANE_SIDE(ent->v.absmin, ent->v.absmax, splitplane);
398 // recurse down the contacted sides
399 // LordHavoc: optimized recursion
400 // if (sides & 1) SV_FindTouchedLeafs (ent, node->children[0]);
401 // if (sides & 2) SV_FindTouchedLeafs (ent, node->children[1]);
405 node = node->children[0];
408 node = node->children[1];
411 if (node->children[0]->contents != CONTENTS_SOLID)
412 SV_FindTouchedLeafs (ent, node->children[0]);
413 node = node->children[1];
424 void SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
429 SV_UnlinkEdict (ent); // unlink from old position
431 if (ent == sv.edicts)
432 return; // don't add the world
439 // LordHavoc: enabling rotating bmodels
440 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
441 { // expand for rotation
445 max = DotProduct(ent->v.mins, ent->v.mins);
446 v = DotProduct(ent->v.maxs, ent->v.maxs);
452 for (i=0 ; i<3 ; i++)
454 v = fabs(ent->v.mins[i]);
457 v = fabs(ent->v.maxs[i]);
462 for (i=0 ; i<3 ; i++)
464 ent->v.absmin[i] = ent->v.origin[i] - max;
465 ent->v.absmax[i] = ent->v.origin[i] + max;
470 VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
471 VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
475 // to make items easier to pick up and allow them to be grabbed off
476 // of shelves, the abs sizes are expanded
478 if ((int)ent->v.flags & FL_ITEM)
480 ent->v.absmin[0] -= 15;
481 ent->v.absmin[1] -= 15;
482 ent->v.absmax[0] += 15;
483 ent->v.absmax[1] += 15;
486 { // because movement is clipped an epsilon away from an actual edge,
487 // we must fully check even when bounding boxes don't quite touch
488 ent->v.absmin[0] -= 1;
489 ent->v.absmin[1] -= 1;
490 ent->v.absmin[2] -= 1;
491 ent->v.absmax[0] += 1;
492 ent->v.absmax[1] += 1;
493 ent->v.absmax[2] += 1;
498 if (ent->v.modelindex)
499 SV_FindTouchedLeafs (ent, sv.worldmodel->nodes);
501 if (ent->v.solid == SOLID_NOT)
504 // find the first node that the ent's box crosses
508 if (node->axis == -1)
510 if (ent->v.absmin[node->axis] > node->dist)
511 node = node->children[0];
512 else if (ent->v.absmax[node->axis] < node->dist)
513 node = node->children[1];
515 break; // crosses the node
520 if (ent->v.solid == SOLID_TRIGGER)
521 InsertLinkBefore (&ent->area, &node->trigger_edicts);
523 InsertLinkBefore (&ent->area, &node->solid_edicts);
525 // if touch_triggers, touch all entities at this node and descend for more
527 SV_TouchLinks ( ent, sv_areanodes );
533 ===============================================================================
535 POINT TESTING IN HULLS
537 ===============================================================================
546 int SV_HullPointContents (hull_t *hull, int num, vec3_t p)
549 num = hull->clipnodes[num].children[(hull->planes[hull->clipnodes[num].planenum].type < 3 ? p[hull->planes[hull->clipnodes[num].planenum].type] : DotProduct (hull->planes[hull->clipnodes[num].planenum].normal, p)) < hull->planes[hull->clipnodes[num].planenum].dist];
556 SV_TestEntityPosition
558 This could be a lot more efficient...
561 edict_t *SV_TestEntityPosition (edict_t *ent)
565 trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, ent->v.origin, 0, ent);
567 if (trace.startsolid)
575 ===============================================================================
577 LINE TESTING IN HULLS
579 ===============================================================================
582 // 1/32 epsilon to keep floating point happy
583 #define DIST_EPSILON (0.03125)
587 SV_RecursiveHullCheck
592 qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace)
607 if (num != CONTENTS_SOLID)
609 trace->allsolid = false;
610 if (num == CONTENTS_EMPTY)
611 trace->inopen = true;
613 trace->inwater = true;
616 trace->startsolid = true;
617 return true; // empty
620 if (num < hull->firstclipnode || num > hull->lastclipnode)
621 Sys_Error ("SV_RecursiveHullCheck: bad node number");
624 // find the point distances
626 node = hull->clipnodes + num;
627 plane = hull->planes + node->planenum;
629 t1 = PlaneDiff(p1, plane);
630 t2 = PlaneDiff(p2, plane);
633 if (t1 >= 0 && t2 >= 0)
634 // LordHavoc: optimized recursion
635 // return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
637 num = node->children[0];
640 if (t1 < 0 && t2 < 0)
641 // return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
643 num = node->children[1];
647 if ( (t1 >= DIST_EPSILON && t2 >= DIST_EPSILON) || (t2 > t1 && t1 >= 0) )
648 return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
649 if ( (t1 <= -DIST_EPSILON && t2 <= -DIST_EPSILON) || (t2 < t1 && t1 <= 0) )
650 return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
653 // put the crosspoint DIST_EPSILON pixels on the near side
655 frac = bound(0, (t1 + DIST_EPSILON)/(t1-t2), 1);
657 frac = bound(0, (t1 - DIST_EPSILON)/(t1-t2), 1);
659 midf = p1f + (p2f - p1f)*frac;
660 mid[0] = p1[0] + frac*(p2[0] - p1[0]);
661 mid[1] = p1[1] + frac*(p2[1] - p1[1]);
662 mid[2] = p1[2] + frac*(p2[2] - p1[2]);
666 // move up to the node
667 if (!SV_RecursiveHullCheck (hull, node->children[side], p1f, midf, p1, mid, trace) )
671 if (SV_HullPointContents (hull, node->children[side], mid) == CONTENTS_SOLID)
673 Con_Printf ("mid PointInHullSolid\n");
678 if (SV_HullPointContents (hull, node->children[side^1], mid) != CONTENTS_SOLID)
680 return SV_RecursiveHullCheck (hull, node->children[side^1], midf, p2f, mid, p2, trace);
681 // mid would need to be duplicated during recursion...
687 num = node->children[side^1];
694 return false; // never got out of the solid area
697 // the other side of the node is solid, this is the impact point
701 VectorCopy (plane->normal, trace->plane.normal);
702 trace->plane.dist = plane->dist;
706 VectorNegate (plane->normal, trace->plane.normal);
707 trace->plane.dist = -plane->dist;
710 while (SV_HullPointContents (hull, hull->firstclipnode, mid) == CONTENTS_SOLID)
711 { // shouldn't really happen, but does occasionally
715 trace->fraction = midf;
716 VectorCopy (mid, trace->endpos);
717 Con_DPrintf ("backup past 0\n");
720 midf = p1f + (p2f - p1f)*frac;
721 for (i=0 ; i<3 ; i++)
722 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
725 trace->fraction = midf;
726 VectorCopy (mid, trace->endpos);
732 // LordHavoc: backported from my optimizations to PM_RecursiveHullCheck in QuakeForge newtree (QW)
733 qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace)
744 // LordHavoc: a goto! everyone flee in terror... :)
749 if (num != CONTENTS_SOLID)
751 trace->allsolid = false;
752 if (num == CONTENTS_EMPTY)
753 trace->inopen = true;
755 trace->inwater = true;
758 trace->startsolid = true;
759 return true; // empty
762 // find the point distances
763 node = hull->clipnodes + num;
764 plane = hull->planes + node->planenum;
768 t1 = p1[plane->type] - plane->dist;
769 t2 = p2[plane->type] - plane->dist;
773 t1 = DotProduct (plane->normal, p1) - plane->dist;
774 t2 = DotProduct (plane->normal, p2) - plane->dist;
777 // LordHavoc: recursion optimization
778 if (t1 >= 0 && t2 >= 0)
780 num = node->children[0];
783 if (t1 < 0 && t2 < 0)
785 num = node->children[1];
789 // put the crosspoint DIST_EPSILON pixels on the near side
792 frac = bound(0, (t1 + DIST_EPSILON) / (t1 - t2), 1);
794 frac = bound(0, (t1 - DIST_EPSILON) / (t1 - t2), 1);
796 midf = p1f + (p2f - p1f)*frac;
797 for (i=0 ; i<3 ; i++)
798 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
800 // move up to the node
801 if (!SV_RecursiveHullCheck (hull, node->children[side], p1f, midf, p1, mid, trace) )
805 if (SV_HullPointContents (pm_hullmodel, mid, node->children[side]) == CONTENTS_SOLID)
807 Con_Printf ("mid PointInHullSolid\n");
812 // LordHavoc: warning to the clumsy, this recursion can not be optimized because mid would need to be duplicated on a stack
813 if (SV_HullPointContents (hull, node->children[side^1], mid) != CONTENTS_SOLID)
815 return SV_RecursiveHullCheck (hull, node->children[side^1], midf, p2f, mid, p2, trace);
818 return false; // never got out of the solid area
821 // the other side of the node is solid, this is the impact point
825 VectorCopy (plane->normal, trace->plane.normal);
826 trace->plane.dist = plane->dist;
830 VectorNegate (plane->normal, trace->plane.normal);
831 trace->plane.dist = -plane->dist;
834 while (SV_HullPointContents (hull, hull->firstclipnode, mid) == CONTENTS_SOLID)
835 { // shouldn't really happen, but does occasionally
839 trace->fraction = midf;
840 VectorCopy (mid, trace->endpos);
841 Con_DPrintf ("backup past 0\n");
844 midf = p1f + (p2f - p1f)*frac;
845 for (i=0 ; i<3 ; i++)
846 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
849 trace->fraction = midf;
850 VectorCopy (mid, trace->endpos);
855 qboolean SV_TestLine (hull_t *hull, int num, vec3_t p1, vec3_t p2)
866 return num != CONTENTS_SOLID;
868 if (num < hull->firstclipnode || num > hull->lastclipnode)
869 Sys_Error ("SV_RecursiveHullCheck: bad node number");
872 // find the point distances
874 node = hull->clipnodes + num;
875 plane = hull->planes + node->planenum;
877 t1 = PlaneDiff(p1, plane);
878 t2 = PlaneDiff(p2, plane);
880 if (t1 >= 0 && t2 >= 0)
882 num = node->children[0];
885 if (t1 < 0 && t2 < 0)
887 num = node->children[1];
891 // put the crosspoint DIST_EPSILON pixels on the near side
895 frac = bound(0, (t1 + DIST_EPSILON)/(t1-t2), 1);
897 frac = bound(0, (t1 - DIST_EPSILON)/(t1-t2), 1);
899 mid[0] = p1[0] + frac*(p2[0] - p1[0]);
900 mid[1] = p1[1] + frac*(p2[1] - p1[1]);
901 mid[2] = p1[2] + frac*(p2[2] - p1[2]);
903 if (node->children[side] < 0)
905 if (node->children[side] == CONTENTS_SOLID)
907 return SV_TestLine(hull, node->children[!side], mid, p2);
909 else if (SV_TestLine(hull, node->children[side], p1, mid))
910 return SV_TestLine(hull, node->children[!side], mid, p2);
920 Handles selection or creation of a clipping hull, and offseting (and
921 eventually rotation) of the end points
924 trace_t SV_ClipMoveToEntity (edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
928 vec3_t start_l, end_l;
931 // fill in a default trace
932 memset (&trace, 0, sizeof(trace_t));
934 trace.allsolid = true;
935 VectorCopy (end, trace.endpos);
937 // get the clipping hull
938 hull = SV_HullForEntity (ent, mins, maxs, offset);
940 VectorSubtract (start, offset, start_l);
941 VectorSubtract (end, offset, end_l);
943 // LordHavoc: enabling rotating bmodels
944 // rotate start and end into the models frame of reference
945 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
947 vec3_t forward, right, up;
950 AngleVectors (ent->v.angles, forward, right, up);
952 VectorCopy (start_l, temp);
953 start_l[0] = DotProduct (temp, forward);
954 start_l[1] = -DotProduct (temp, right);
955 start_l[2] = DotProduct (temp, up);
957 VectorCopy (end_l, temp);
958 end_l[0] = DotProduct (temp, forward);
959 end_l[1] = -DotProduct (temp, right);
960 end_l[2] = DotProduct (temp, up);
963 // trace a line through the apropriate clipping hull
964 SV_RecursiveHullCheck (hull, hull->firstclipnode, 0, 1, start_l, end_l, &trace);
966 // LordHavoc: enabling rotating bmodels
967 // rotate endpos back to world frame of reference
968 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
971 vec3_t forward, right, up;
974 if (trace.fraction != 1)
976 VectorNegate (ent->v.angles, a);
977 AngleVectors (a, forward, right, up);
979 VectorCopy (trace.endpos, temp);
980 trace.endpos[0] = DotProduct (temp, forward);
981 trace.endpos[1] = -DotProduct (temp, right);
982 trace.endpos[2] = DotProduct (temp, up);
984 VectorCopy (trace.plane.normal, temp);
985 trace.plane.normal[0] = DotProduct (temp, forward);
986 trace.plane.normal[1] = -DotProduct (temp, right);
987 trace.plane.normal[2] = DotProduct (temp, up);
991 // fix trace up by the offset
992 if (trace.fraction != 1)
993 VectorAdd (trace.endpos, offset, trace.endpos);
995 // did we clip the move?
996 if (trace.fraction < 1 || trace.startsolid )
1002 //===========================================================================
1005 ====================
1008 Mins and maxs enclose the entire area swept by the move
1009 ====================
1011 void SV_ClipToLinks ( areanode_t *node, moveclip_t *clip )
1018 // touch linked edicts
1019 for (l = node->solid_edicts.next ; l != &node->solid_edicts ; l = next)
1022 touch = EDICT_FROM_AREA(l);
1023 if (touch->v.solid == SOLID_NOT)
1025 if (touch == clip->passedict)
1027 if (touch->v.solid == SOLID_TRIGGER)
1028 Sys_Error ("Trigger in clipping list");
1030 if (clip->type == MOVE_NOMONSTERS && touch->v.solid != SOLID_BSP)
1033 if (clip->boxmins[0] > touch->v.absmax[0]
1034 || clip->boxmins[1] > touch->v.absmax[1]
1035 || clip->boxmins[2] > touch->v.absmax[2]
1036 || clip->boxmaxs[0] < touch->v.absmin[0]
1037 || clip->boxmaxs[1] < touch->v.absmin[1]
1038 || clip->boxmaxs[2] < touch->v.absmin[2] )
1041 if (clip->passedict!=0 && clip->passedict->v.size[0] && !touch->v.size[0])
1042 continue; // points never interact
1044 // might intersect, so do an exact clip
1045 if (clip->trace.allsolid)
1047 if (clip->passedict)
1049 if (PROG_TO_EDICT(touch->v.owner) == clip->passedict)
1050 continue; // don't clip against own missiles
1051 if (PROG_TO_EDICT(clip->passedict->v.owner) == touch)
1052 continue; // don't clip against owner
1053 // LordHavoc: corpse code
1054 if (clip->passedict->v.solid == SOLID_CORPSE && touch->v.solid == SOLID_SLIDEBOX)
1056 if (clip->passedict->v.solid == SOLID_SLIDEBOX && touch->v.solid == SOLID_CORPSE)
1060 if ((int)touch->v.flags & FL_MONSTER)
1061 trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins2, clip->maxs2, clip->end);
1063 trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins, clip->maxs, clip->end);
1064 if (trace.allsolid || trace.startsolid || trace.fraction < clip->trace.fraction)
1067 if (clip->trace.startsolid)
1069 clip->trace = trace;
1070 clip->trace.startsolid = true;
1073 clip->trace = trace;
1075 else if (trace.startsolid)
1076 clip->trace.startsolid = true;
1079 // recurse down both sides
1080 if (node->axis == -1)
1083 // LordHavoc: optimized recursion
1084 // if (clip->boxmaxs[node->axis] > node->dist) SV_ClipToLinks(node->children[0], clip);
1085 // if (clip->boxmins[node->axis] < node->dist) SV_ClipToLinks(node->children[1], clip);
1086 if (clip->boxmaxs[node->axis] > node->dist)
1088 if (clip->boxmins[node->axis] < node->dist)
1089 SV_ClipToLinks(node->children[1], clip);
1090 node = node->children[0];
1093 else if (clip->boxmins[node->axis] < node->dist)
1095 node = node->children[1];
1106 void SV_MoveBounds (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, vec3_t boxmins, vec3_t boxmaxs)
1109 // debug to test against everything
1110 boxmins[0] = boxmins[1] = boxmins[2] = -9999;
1111 boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 9999;
1115 for (i=0 ; i<3 ; i++)
1117 if (end[i] > start[i])
1119 boxmins[i] = start[i] + mins[i] - 1;
1120 boxmaxs[i] = end[i] + maxs[i] + 1;
1124 boxmins[i] = end[i] + mins[i] - 1;
1125 boxmaxs[i] = start[i] + maxs[i] + 1;
1136 trace_t SV_Move (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict)
1141 memset ( &clip, 0, sizeof ( moveclip_t ) );
1144 clip.trace = SV_ClipMoveToEntity ( sv.edicts, start, mins, maxs, end );
1151 clip.passedict = passedict;
1153 if (type == MOVE_MISSILE)
1155 for (i=0 ; i<3 ; i++)
1157 clip.mins2[i] = -15;
1163 VectorCopy (mins, clip.mins2);
1164 VectorCopy (maxs, clip.maxs2);
1167 // create the bounding box of the entire move
1168 SV_MoveBounds ( start, clip.mins2, clip.maxs2, end, clip.boxmins, clip.boxmaxs );
1171 SV_ClipToLinks ( sv_areanodes, &clip );