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 struct link_s *prev, *next;
40 void ClearLink (link_t *l);
41 void RemoveLink (link_t *l);
42 void InsertLinkBefore (link_t *l, link_t *before);
43 void InsertLinkAfter (link_t *l, link_t *after);
45 // (type *)STRUCT_FROM_LINK(link_t *link, type, member)
46 // ent = STRUCT_FROM_LINK(link,entity_t,order)
47 // FIXME: remove this mess!
48 //#define STRUCT_FROM_LINK(l,t,m) ((t *)((byte *)l - (int)&(((t *)0)->m)))
50 #define EDICT_FROM_AREA(l) ((edict_t *)((byte *)l - (int)&(((edict_t *)0)->area)))
52 //============================================================================
54 // ClearLink is used for new headnodes
55 void ClearLink (link_t *l)
57 l->prev = l->next = l;
60 void RemoveLink (link_t *l)
62 l->next->prev = l->prev;
63 l->prev->next = l->next;
66 void InsertLinkBefore (link_t *l, link_t *before)
69 l->prev = before->prev;
73 void InsertLinkAfter (link_t *l, link_t *after)
75 l->next = after->next;
84 vec3_t boxmins, boxmaxs;// enclose the test object along entire move
85 float *mins, *maxs; // size of the moving object
86 vec3_t mins2, maxs2; // size when clipping against mosnters
95 ===============================================================================
99 ===============================================================================
103 static hull_t box_hull;
104 static dclipnode_t box_clipnodes[6];
105 static mplane_t box_planes[6];
111 Set up the planes and clipnodes so that the six floats of a bounding box
112 can just be stored out and get a proper hull_t structure.
115 void SV_InitBoxHull (void)
120 box_hull.clipnodes = box_clipnodes;
121 box_hull.planes = box_planes;
122 box_hull.firstclipnode = 0;
123 box_hull.lastclipnode = 5;
125 for (i=0 ; i<6 ; i++)
127 box_clipnodes[i].planenum = i;
131 box_clipnodes[i].children[side] = CONTENTS_EMPTY;
133 box_clipnodes[i].children[side^1] = i + 1;
135 box_clipnodes[i].children[side^1] = CONTENTS_SOLID;
137 box_planes[i].type = i>>1;
138 box_planes[i].normal[i>>1] = 1;
148 To keep everything totally uniform, bounding boxes are turned into small
149 BSP trees instead of being compared directly.
152 hull_t *SV_HullForBox (vec3_t mins, vec3_t maxs)
154 box_planes[0].dist = maxs[0];
155 box_planes[1].dist = mins[0];
156 box_planes[2].dist = maxs[1];
157 box_planes[3].dist = mins[1];
158 box_planes[4].dist = maxs[2];
159 box_planes[5].dist = mins[2];
170 Returns a hull that can be used for testing or clipping an object of mins/maxs
172 Offset is filled in to contain the adjustment that must be added to the
173 testing object's origin to get a point to use with the returned hull.
176 hull_t *SV_HullForEntity (edict_t *ent, vec3_t mins, vec3_t maxs, vec3_t offset)
180 vec3_t hullmins, hullmaxs;
183 // decide which clipping hull to use, based on the size
184 if (ent->v.solid == SOLID_BSP)
185 { // explicit hulls in the BSP model
186 if (ent->v.movetype != MOVETYPE_PUSH)
187 Host_Error ("SOLID_BSP without MOVETYPE_PUSH");
189 model = sv.models[ (int)ent->v.modelindex ];
191 // LordHavoc: fixed SOLID_BSP error message
192 if (!model || model->type != mod_brush)
194 Con_Printf ("SOLID_BSP with a non bsp model, entity dump:\n");
196 Host_Error ("SOLID_BSP with a non bsp model\n");
199 VectorSubtract (maxs, mins, size);
200 // LordHavoc: FIXME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
204 hull = &model->hulls[0]; // 0x0x0
205 else if (size[0] <= 32)
207 if (size[2] < 54) // pick the nearest of 36 or 72
208 hull = &model->hulls[3]; // 32x32x36
210 hull = &model->hulls[1]; // 32x32x72
213 hull = &model->hulls[2]; // 64x64x64
218 hull = &model->hulls[0]; // 0x0x0
219 else if (size[0] <= 32)
220 hull = &model->hulls[1]; // 32x32x56
222 hull = &model->hulls[2]; // 64x64x88
225 // calculate an offset value to center the origin
226 VectorSubtract (hull->clip_mins, mins, offset);
227 VectorAdd (offset, ent->v.origin, offset);
230 { // create a temp hull from bounding box sizes
232 VectorSubtract (ent->v.mins, maxs, hullmins);
233 VectorSubtract (ent->v.maxs, mins, hullmaxs);
234 hull = SV_HullForBox (hullmins, hullmaxs);
236 VectorCopy (ent->v.origin, offset);
244 ===============================================================================
248 ===============================================================================
251 typedef struct areanode_s
253 int axis; // -1 = leaf node
255 struct areanode_s *children[2];
256 link_t trigger_edicts;
261 #define AREA_NODES 32
263 static areanode_t sv_areanodes[AREA_NODES];
264 static int sv_numareanodes;
272 areanode_t *SV_CreateAreaNode (int depth, vec3_t mins, vec3_t maxs)
276 vec3_t mins1, maxs1, mins2, maxs2;
278 anode = &sv_areanodes[sv_numareanodes];
281 ClearLink (&anode->trigger_edicts);
282 ClearLink (&anode->solid_edicts);
284 if (depth == AREA_DEPTH)
287 anode->children[0] = anode->children[1] = NULL;
291 VectorSubtract (maxs, mins, size);
292 if (size[0] > size[1])
297 anode->dist = 0.5 * (maxs[anode->axis] + mins[anode->axis]);
298 VectorCopy (mins, mins1);
299 VectorCopy (mins, mins2);
300 VectorCopy (maxs, maxs1);
301 VectorCopy (maxs, maxs2);
303 maxs1[anode->axis] = mins2[anode->axis] = anode->dist;
305 anode->children[0] = SV_CreateAreaNode (depth+1, mins2, maxs2);
306 anode->children[1] = SV_CreateAreaNode (depth+1, mins1, maxs1);
317 void SV_ClearWorld (void)
321 memset (sv_areanodes, 0, sizeof(sv_areanodes));
323 SV_CreateAreaNode (0, sv.worldmodel->mins, sv.worldmodel->maxs);
333 void SV_UnlinkEdict (edict_t *ent)
336 return; // not linked in anywhere
337 RemoveLink (&ent->area);
338 ent->area.prev = ent->area.next = NULL;
347 void SV_TouchLinks ( edict_t *ent, areanode_t *node )
351 int old_self, old_other;
354 // touch linked edicts
355 for (l = node->trigger_edicts.next ; l != &node->trigger_edicts ; l = next)
358 touch = EDICT_FROM_AREA(l);
361 if (!touch->v.touch || touch->v.solid != SOLID_TRIGGER)
363 if (ent->v.absmin[0] > touch->v.absmax[0]
364 || ent->v.absmin[1] > touch->v.absmax[1]
365 || ent->v.absmin[2] > touch->v.absmax[2]
366 || ent->v.absmax[0] < touch->v.absmin[0]
367 || ent->v.absmax[1] < touch->v.absmin[1]
368 || ent->v.absmax[2] < touch->v.absmin[2])
370 old_self = pr_global_struct->self;
371 old_other = pr_global_struct->other;
373 pr_global_struct->self = EDICT_TO_PROG(touch);
374 pr_global_struct->other = EDICT_TO_PROG(ent);
375 pr_global_struct->time = sv.time;
376 PR_ExecuteProgram (touch->v.touch, "");
378 pr_global_struct->self = old_self;
379 pr_global_struct->other = old_other;
382 // recurse down both sides
383 if (node->axis == -1)
386 // LordHavoc: optimized recursion
387 // if (ent->v.absmax[node->axis] > node->dist) SV_TouchLinks (ent, node->children[0]);
388 // if (ent->v.absmin[node->axis] < node->dist) SV_TouchLinks (ent, node->children[1]);
389 if (ent->v.absmax[node->axis] > node->dist)
391 if (ent->v.absmin[node->axis] < node->dist)
392 SV_TouchLinks(ent, node->children[1]); // order reversed to reduce code
393 node = node->children[0];
398 if (ent->v.absmin[node->axis] < node->dist)
400 node = node->children[1];
413 void SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
418 SV_UnlinkEdict (ent); // unlink from old position
420 if (ent == sv.edicts)
421 return; // don't add the world
428 // LordHavoc: enabling rotating bmodels
429 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
431 // expand for rotation
435 max = DotProduct(ent->v.mins, ent->v.mins);
436 v = DotProduct(ent->v.maxs, ent->v.maxs);
442 for (i=0 ; i<3 ; i++)
444 v = fabs(ent->v.mins[i]);
447 v = fabs(ent->v.maxs[i]);
452 for (i=0 ; i<3 ; i++)
454 ent->v.absmin[i] = ent->v.origin[i] - max;
455 ent->v.absmax[i] = ent->v.origin[i] + max;
460 VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
461 VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
465 // to make items easier to pick up and allow them to be grabbed off
466 // of shelves, the abs sizes are expanded
468 if ((int)ent->v.flags & FL_ITEM)
470 ent->v.absmin[0] -= 15;
471 ent->v.absmin[1] -= 15;
472 ent->v.absmax[0] += 15;
473 ent->v.absmax[1] += 15;
477 // because movement is clipped an epsilon away from an actual edge,
478 // we must fully check even when bounding boxes don't quite touch
479 ent->v.absmin[0] -= 1;
480 ent->v.absmin[1] -= 1;
481 ent->v.absmin[2] -= 1;
482 ent->v.absmax[0] += 1;
483 ent->v.absmax[1] += 1;
484 ent->v.absmax[2] += 1;
487 if (ent->v.solid == SOLID_NOT)
490 // find the first node that the ent's box crosses
494 if (node->axis == -1)
496 if (ent->v.absmin[node->axis] > node->dist)
497 node = node->children[0];
498 else if (ent->v.absmax[node->axis] < node->dist)
499 node = node->children[1];
501 break; // crosses the node
506 if (ent->v.solid == SOLID_TRIGGER)
507 InsertLinkBefore (&ent->area, &node->trigger_edicts);
509 InsertLinkBefore (&ent->area, &node->solid_edicts);
511 // if touch_triggers, touch all entities at this node and descend for more
513 SV_TouchLinks ( ent, sv_areanodes );
519 ===============================================================================
521 POINT TESTING IN HULLS
523 ===============================================================================
532 int SV_HullPointContents (hull_t *hull, int num, vec3_t p)
535 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];
542 SV_TestEntityPosition
544 This could be a lot more efficient...
547 edict_t *SV_TestEntityPosition (edict_t *ent)
551 trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, ent->v.origin, MOVE_NORMAL, ent);
553 if (trace.startsolid)
561 ===============================================================================
563 LINE TESTING IN HULLS
565 ===============================================================================
568 // 1/32 epsilon to keep floating point happy
569 #define DIST_EPSILON (0.03125)
573 SV_RecursiveHullCheck
578 qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace)
593 if (num != CONTENTS_SOLID)
595 trace->allsolid = false;
596 if (num == CONTENTS_EMPTY)
597 trace->inopen = true;
599 trace->inwater = true;
602 trace->startsolid = true;
603 return true; // empty
606 if (num < hull->firstclipnode || num > hull->lastclipnode)
607 Sys_Error ("SV_RecursiveHullCheck: bad node number");
610 // find the point distances
612 node = hull->clipnodes + num;
613 plane = hull->planes + node->planenum;
615 t1 = PlaneDiff(p1, plane);
616 t2 = PlaneDiff(p2, plane);
619 if (t1 >= 0 && t2 >= 0)
620 // LordHavoc: optimized recursion
621 // return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
623 num = node->children[0];
626 if (t1 < 0 && t2 < 0)
627 // return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
629 num = node->children[1];
633 if ( (t1 >= DIST_EPSILON && t2 >= DIST_EPSILON) || (t2 > t1 && t1 >= 0) )
634 return SV_RecursiveHullCheck (hull, node->children[0], p1f, p2f, p1, p2, trace);
635 if ( (t1 <= -DIST_EPSILON && t2 <= -DIST_EPSILON) || (t2 < t1 && t1 <= 0) )
636 return SV_RecursiveHullCheck (hull, node->children[1], p1f, p2f, p1, p2, trace);
639 // put the crosspoint DIST_EPSILON pixels on the near side
641 frac = bound(0, (t1 + DIST_EPSILON)/(t1-t2), 1);
643 frac = bound(0, (t1 - DIST_EPSILON)/(t1-t2), 1);
645 midf = p1f + (p2f - p1f)*frac;
646 mid[0] = p1[0] + frac*(p2[0] - p1[0]);
647 mid[1] = p1[1] + frac*(p2[1] - p1[1]);
648 mid[2] = p1[2] + frac*(p2[2] - p1[2]);
652 // move up to the node
653 if (!SV_RecursiveHullCheck (hull, node->children[side], p1f, midf, p1, mid, trace) )
657 if (SV_HullPointContents (hull, node->children[side], mid) == CONTENTS_SOLID)
659 Con_Printf ("mid PointInHullSolid\n");
664 if (SV_HullPointContents (hull, node->children[side^1], mid) != CONTENTS_SOLID)
666 return SV_RecursiveHullCheck (hull, node->children[side^1], midf, p2f, mid, p2, trace);
667 // mid would need to be duplicated during recursion...
673 num = node->children[side^1];
680 return false; // never got out of the solid area
683 // the other side of the node is solid, this is the impact point
687 VectorCopy (plane->normal, trace->plane.normal);
688 trace->plane.dist = plane->dist;
692 VectorNegate (plane->normal, trace->plane.normal);
693 trace->plane.dist = -plane->dist;
696 while (SV_HullPointContents (hull, hull->firstclipnode, mid) == CONTENTS_SOLID)
697 { // shouldn't really happen, but does occasionally
701 trace->fraction = midf;
702 VectorCopy (mid, trace->endpos);
703 Con_DPrintf ("backup past 0\n");
706 midf = p1f + (p2f - p1f)*frac;
707 for (i=0 ; i<3 ; i++)
708 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
711 trace->fraction = midf;
712 VectorCopy (mid, trace->endpos);
718 // LordHavoc: backported from my optimizations to PM_RecursiveHullCheck in QuakeForge newtree (QW)
719 qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace)
730 // LordHavoc: a goto! everyone flee in terror... :)
735 if (num != CONTENTS_SOLID)
737 trace->allsolid = false;
738 if (num == CONTENTS_EMPTY)
739 trace->inopen = true;
741 trace->inwater = true;
744 trace->startsolid = true;
745 return true; // empty
748 // find the point distances
749 node = hull->clipnodes + num;
750 plane = hull->planes + node->planenum;
754 t1 = p1[plane->type] - plane->dist;
755 t2 = p2[plane->type] - plane->dist;
759 t1 = DotProduct (plane->normal, p1) - plane->dist;
760 t2 = DotProduct (plane->normal, p2) - plane->dist;
763 // LordHavoc: recursion optimization
764 if (t1 >= 0 && t2 >= 0)
766 num = node->children[0];
769 if (t1 < 0 && t2 < 0)
771 num = node->children[1];
775 // put the crosspoint DIST_EPSILON pixels on the near side
778 frac = bound(0, (t1 + DIST_EPSILON) / (t1 - t2), 1);
780 frac = bound(0, (t1 - DIST_EPSILON) / (t1 - t2), 1);
782 midf = p1f + (p2f - p1f)*frac;
783 for (i=0 ; i<3 ; i++)
784 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
786 // move up to the node
787 if (!SV_RecursiveHullCheck (hull, node->children[side], p1f, midf, p1, mid, trace) )
791 if (SV_HullPointContents (pm_hullmodel, mid, node->children[side]) == CONTENTS_SOLID)
793 Con_Printf ("mid PointInHullSolid\n");
798 // LordHavoc: warning to the clumsy, this recursion can not be optimized because mid would need to be duplicated on a stack
799 if (SV_HullPointContents (hull, node->children[side^1], mid) != CONTENTS_SOLID)
801 return SV_RecursiveHullCheck (hull, node->children[side^1], midf, p2f, mid, p2, trace);
804 return false; // never got out of the solid area
807 // the other side of the node is solid, this is the impact point
811 VectorCopy (plane->normal, trace->plane.normal);
812 trace->plane.dist = plane->dist;
816 VectorNegate (plane->normal, trace->plane.normal);
817 trace->plane.dist = -plane->dist;
820 while (SV_HullPointContents (hull, hull->firstclipnode, mid) == CONTENTS_SOLID)
821 { // shouldn't really happen, but does occasionally
825 trace->fraction = midf;
826 VectorCopy (mid, trace->endpos);
827 Con_DPrintf ("backup past 0\n");
830 midf = p1f + (p2f - p1f)*frac;
831 for (i=0 ; i<3 ; i++)
832 mid[i] = p1[i] + frac*(p2[i] - p1[i]);
835 trace->fraction = midf;
836 VectorCopy (mid, trace->endpos);
841 qboolean SV_TestLine (hull_t *hull, int num, vec3_t p1, vec3_t p2)
852 return num != CONTENTS_SOLID;
854 if (num < hull->firstclipnode || num > hull->lastclipnode)
855 Sys_Error ("SV_RecursiveHullCheck: bad node number");
858 // find the point distances
860 node = hull->clipnodes + num;
861 plane = hull->planes + node->planenum;
863 t1 = PlaneDiff(p1, plane);
864 t2 = PlaneDiff(p2, plane);
866 if (t1 >= 0 && t2 >= 0)
868 num = node->children[0];
871 if (t1 < 0 && t2 < 0)
873 num = node->children[1];
877 // put the crosspoint DIST_EPSILON pixels on the near side
881 frac = bound(0, (t1 + DIST_EPSILON)/(t1-t2), 1);
883 frac = bound(0, (t1 - DIST_EPSILON)/(t1-t2), 1);
885 mid[0] = p1[0] + frac*(p2[0] - p1[0]);
886 mid[1] = p1[1] + frac*(p2[1] - p1[1]);
887 mid[2] = p1[2] + frac*(p2[2] - p1[2]);
889 if (node->children[side] < 0)
891 if (node->children[side] == CONTENTS_SOLID)
893 return SV_TestLine(hull, node->children[!side], mid, p2);
895 else if (SV_TestLine(hull, node->children[side], p1, mid))
896 return SV_TestLine(hull, node->children[!side], mid, p2);
906 Handles selection or creation of a clipping hull, and offseting (and
907 eventually rotation) of the end points
910 trace_t SV_ClipMoveToEntity (edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
914 vec3_t start_l, end_l;
917 // fill in a default trace
918 memset (&trace, 0, sizeof(trace_t));
920 trace.allsolid = true;
921 VectorCopy (end, trace.endpos);
923 // get the clipping hull
924 hull = SV_HullForEntity (ent, mins, maxs, offset);
926 VectorSubtract (start, offset, start_l);
927 VectorSubtract (end, offset, end_l);
929 // LordHavoc: enabling rotating bmodels
930 // rotate start and end into the models frame of reference
931 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
933 vec3_t forward, right, up;
936 AngleVectors (ent->v.angles, forward, right, up);
938 VectorCopy (start_l, temp);
939 start_l[0] = DotProduct (temp, forward);
940 start_l[1] = -DotProduct (temp, right);
941 start_l[2] = DotProduct (temp, up);
943 VectorCopy (end_l, temp);
944 end_l[0] = DotProduct (temp, forward);
945 end_l[1] = -DotProduct (temp, right);
946 end_l[2] = DotProduct (temp, up);
949 // trace a line through the apropriate clipping hull
950 SV_RecursiveHullCheck (hull, hull->firstclipnode, 0, 1, start_l, end_l, &trace);
952 // LordHavoc: enabling rotating bmodels
953 // rotate endpos back to world frame of reference
954 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
957 vec3_t forward, right, up;
960 if (trace.fraction != 1)
962 VectorNegate (ent->v.angles, a);
963 AngleVectors (a, forward, right, up);
965 VectorCopy (trace.endpos, temp);
966 trace.endpos[0] = DotProduct (temp, forward);
967 trace.endpos[1] = -DotProduct (temp, right);
968 trace.endpos[2] = DotProduct (temp, up);
970 VectorCopy (trace.plane.normal, temp);
971 trace.plane.normal[0] = DotProduct (temp, forward);
972 trace.plane.normal[1] = -DotProduct (temp, right);
973 trace.plane.normal[2] = DotProduct (temp, up);
977 // fix trace up by the offset
978 if (trace.fraction != 1)
979 VectorAdd (trace.endpos, offset, trace.endpos);
981 // did we clip the move?
982 if (trace.fraction < 1 || trace.startsolid )
988 //===========================================================================
994 Mins and maxs enclose the entire area swept by the move
997 void SV_ClipToLinks ( areanode_t *node, moveclip_t *clip )
1004 // touch linked edicts
1005 for (l = node->solid_edicts.next ; l != &node->solid_edicts ; l = next)
1008 touch = EDICT_FROM_AREA(l);
1009 if (touch->v.solid == SOLID_NOT)
1011 if (touch == clip->passedict)
1013 if (touch->v.solid == SOLID_TRIGGER)
1014 Sys_Error ("Trigger in clipping list");
1016 if (clip->type == MOVE_NOMONSTERS && touch->v.solid != SOLID_BSP)
1019 if (clip->boxmins[0] > touch->v.absmax[0]
1020 || clip->boxmins[1] > touch->v.absmax[1]
1021 || clip->boxmins[2] > touch->v.absmax[2]
1022 || clip->boxmaxs[0] < touch->v.absmin[0]
1023 || clip->boxmaxs[1] < touch->v.absmin[1]
1024 || clip->boxmaxs[2] < touch->v.absmin[2])
1027 if (clip->passedict != NULL && clip->passedict->v.size[0] && !touch->v.size[0])
1028 continue; // points never interact
1030 // might intersect, so do an exact clip
1031 if (clip->trace.allsolid)
1033 if (clip->passedict)
1035 if (PROG_TO_EDICT(touch->v.owner) == clip->passedict)
1036 continue; // don't clip against own missiles
1037 if (PROG_TO_EDICT(clip->passedict->v.owner) == touch)
1038 continue; // don't clip against owner
1039 // LordHavoc: corpse code
1040 if (clip->passedict->v.solid == SOLID_CORPSE && touch->v.solid == SOLID_SLIDEBOX)
1042 if (clip->passedict->v.solid == SOLID_SLIDEBOX && touch->v.solid == SOLID_CORPSE)
1046 if ((int)touch->v.flags & FL_MONSTER)
1047 trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins2, clip->maxs2, clip->end);
1049 trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins, clip->maxs, clip->end);
1050 if (trace.allsolid || trace.startsolid || trace.fraction < clip->trace.fraction)
1053 if (clip->trace.startsolid)
1055 clip->trace = trace;
1056 clip->trace.startsolid = true;
1059 clip->trace = trace;
1061 else if (trace.startsolid)
1062 clip->trace.startsolid = true;
1065 // recurse down both sides
1066 if (node->axis == -1)
1069 // LordHavoc: optimized recursion
1070 // if (clip->boxmaxs[node->axis] > node->dist) SV_ClipToLinks(node->children[0], clip);
1071 // if (clip->boxmins[node->axis] < node->dist) SV_ClipToLinks(node->children[1], clip);
1072 if (clip->boxmaxs[node->axis] > node->dist)
1074 if (clip->boxmins[node->axis] < node->dist)
1075 SV_ClipToLinks(node->children[1], clip);
1076 node = node->children[0];
1079 else if (clip->boxmins[node->axis] < node->dist)
1081 node = node->children[1];
1092 void SV_MoveBounds (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, vec3_t boxmins, vec3_t boxmaxs)
1095 // debug to test against everything
1096 boxmins[0] = boxmins[1] = boxmins[2] = -9999;
1097 boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 9999;
1101 for (i=0 ; i<3 ; i++)
1103 if (end[i] > start[i])
1105 boxmins[i] = start[i] + mins[i] - 1;
1106 boxmaxs[i] = end[i] + maxs[i] + 1;
1110 boxmins[i] = end[i] + mins[i] - 1;
1111 boxmaxs[i] = start[i] + maxs[i] + 1;
1122 trace_t SV_Move (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict)
1127 memset ( &clip, 0, sizeof ( moveclip_t ) );
1130 clip.trace = SV_ClipMoveToEntity ( sv.edicts, start, mins, maxs, end );
1137 clip.passedict = passedict;
1139 if (type == MOVE_MISSILE)
1141 for (i=0 ; i<3 ; i++)
1143 clip.mins2[i] = -15;
1149 VectorCopy (mins, clip.mins2);
1150 VectorCopy (maxs, clip.maxs2);
1153 // create the bounding box of the entire move
1154 SV_MoveBounds ( start, clip.mins2, clip.maxs2, end, clip.boxmins, clip.boxmaxs );
1157 SV_ClipToLinks ( sv_areanodes, &clip );