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 *)((qbyte *)l - (int)&(((t *)0)->m)))
50 #define EDICT_FROM_AREA(l) ((edict_t *)((qbyte *)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 // bounding box of entire move area
85 vec3_t boxmins, boxmaxs;
87 // size of the moving object
90 // size when clipping against monsters
93 // size when clipping against brush models
94 vec3_t hullmins, hullmaxs;
96 // start and end origin of move
102 // type of move (like ignoring monsters, or similar)
105 // the edict that is moving (if any)
112 ===============================================================================
116 ===============================================================================
120 static hull_t box_hull;
121 static dclipnode_t box_clipnodes[6];
122 static mplane_t box_planes[6];
128 Set up the planes and clipnodes so that the six floats of a bounding box
129 can just be stored out and get a proper hull_t structure.
132 void SV_InitBoxHull (void)
137 box_hull.clipnodes = box_clipnodes;
138 box_hull.planes = box_planes;
139 box_hull.firstclipnode = 0;
140 box_hull.lastclipnode = 5;
142 for (i=0 ; i<6 ; i++)
144 box_clipnodes[i].planenum = i;
148 box_clipnodes[i].children[side] = CONTENTS_EMPTY;
150 box_clipnodes[i].children[side^1] = i + 1;
152 box_clipnodes[i].children[side^1] = CONTENTS_SOLID;
154 box_planes[i].type = i>>1;
155 box_planes[i].normal[i>>1] = 1;
164 To keep everything totally uniform, bounding boxes are turned into small
165 BSP trees instead of being compared directly.
168 hull_t *SV_HullForBox (vec3_t mins, vec3_t maxs)
170 box_planes[0].dist = maxs[0];
171 box_planes[1].dist = mins[0];
172 box_planes[2].dist = maxs[1];
173 box_planes[3].dist = mins[1];
174 box_planes[4].dist = maxs[2];
175 box_planes[5].dist = mins[2];
186 Returns a hull that can be used for testing or clipping an object of mins/maxs
188 Offset is filled in to contain the adjustment that must be added to the
189 testing object's origin to get a point to use with the returned hull.
192 hull_t *SV_HullForEntity (edict_t *ent, vec3_t mins, vec3_t maxs, vec3_t offset)
196 vec3_t hullmins, hullmaxs;
199 // decide which clipping hull to use, based on the size
200 if (ent->v.solid == SOLID_BSP)
202 // explicit hulls in the BSP model
203 if (ent->v.movetype != MOVETYPE_PUSH)
204 Host_Error ("SOLID_BSP without MOVETYPE_PUSH");
206 model = sv.models[ (int)ent->v.modelindex ];
207 Mod_CheckLoaded(model);
209 // LordHavoc: fixed SOLID_BSP error message
210 if (!model || model->type != mod_brush)
212 Con_Printf ("SOLID_BSP with a non bsp model, entity dump:\n");
214 Host_Error ("SOLID_BSP with a non bsp model\n");
217 VectorSubtract (maxs, mins, size);
218 // LordHavoc: FIXME!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
222 hull = &model->hulls[0]; // 0x0x0
223 else if (size[0] <= 32)
225 if (size[2] < 54) // pick the nearest of 36 or 72
226 hull = &model->hulls[3]; // 32x32x36
228 hull = &model->hulls[1]; // 32x32x72
231 hull = &model->hulls[2]; // 64x64x64
236 hull = &model->hulls[0]; // 0x0x0
237 else if (size[0] <= 32)
238 hull = &model->hulls[1]; // 32x32x56
240 hull = &model->hulls[2]; // 64x64x88
243 // calculate an offset value to center the origin
244 VectorSubtract (hull->clip_mins, mins, offset);
245 VectorAdd (offset, ent->v.origin, offset);
248 { // create a temp hull from bounding box sizes
250 VectorSubtract (ent->v.mins, maxs, hullmins);
251 VectorSubtract (ent->v.maxs, mins, hullmaxs);
252 hull = SV_HullForBox (hullmins, hullmaxs);
254 VectorCopy (ent->v.origin, offset);
261 void SV_RoundUpToHullSize(vec3_t inmins, vec3_t inmaxs, vec3_t outmins, vec3_t outmaxs)
266 VectorSubtract(inmaxs, inmins, size);
267 if (sv.worldmodel->ishlbsp)
270 hull = &sv.worldmodel->hulls[0]; // 0x0x0
271 else if (size[0] <= 32)
273 if (size[2] < 54) // pick the nearest of 36 or 72
274 hull = &sv.worldmodel->hulls[3]; // 32x32x36
276 hull = &sv.worldmodel->hulls[1]; // 32x32x72
279 hull = &sv.worldmodel->hulls[2]; // 64x64x64
284 hull = &sv.worldmodel->hulls[0]; // 0x0x0
285 else if (size[0] <= 32)
286 hull = &sv.worldmodel->hulls[1]; // 32x32x56
288 hull = &sv.worldmodel->hulls[2]; // 64x64x88
290 VectorCopy(inmins, outmins);
291 VectorAdd(inmins, hull->clip_size, outmaxs);
295 ===============================================================================
299 ===============================================================================
302 typedef struct areanode_s
304 int axis; // -1 = leaf node
306 struct areanode_s *children[2];
307 link_t trigger_edicts;
312 #define AREA_NODES 32
314 static areanode_t sv_areanodes[AREA_NODES];
315 static int sv_numareanodes;
323 areanode_t *SV_CreateAreaNode (int depth, vec3_t mins, vec3_t maxs)
327 vec3_t mins1, maxs1, mins2, maxs2;
329 anode = &sv_areanodes[sv_numareanodes];
332 ClearLink (&anode->trigger_edicts);
333 ClearLink (&anode->solid_edicts);
335 if (depth == AREA_DEPTH)
338 anode->children[0] = anode->children[1] = NULL;
342 VectorSubtract (maxs, mins, size);
343 if (size[0] > size[1])
348 anode->dist = 0.5 * (maxs[anode->axis] + mins[anode->axis]);
349 VectorCopy (mins, mins1);
350 VectorCopy (mins, mins2);
351 VectorCopy (maxs, maxs1);
352 VectorCopy (maxs, maxs2);
354 maxs1[anode->axis] = mins2[anode->axis] = anode->dist;
356 anode->children[0] = SV_CreateAreaNode (depth+1, mins2, maxs2);
357 anode->children[1] = SV_CreateAreaNode (depth+1, mins1, maxs1);
368 void SV_ClearWorld (void)
372 memset (sv_areanodes, 0, sizeof(sv_areanodes));
374 Mod_CheckLoaded(sv.worldmodel);
375 SV_CreateAreaNode (0, sv.worldmodel->normalmins, sv.worldmodel->normalmaxs);
385 void SV_UnlinkEdict (edict_t *ent)
388 return; // not linked in anywhere
389 RemoveLink (&ent->area);
390 ent->area.prev = ent->area.next = NULL;
399 void SV_TouchLinks ( edict_t *ent, areanode_t *node )
403 int old_self, old_other;
406 // touch linked edicts
407 for (l = node->trigger_edicts.next ; l != &node->trigger_edicts ; l = next)
410 touch = EDICT_FROM_AREA(l);
413 if (!touch->v.touch || touch->v.solid != SOLID_TRIGGER)
415 if (ent->v.absmin[0] > touch->v.absmax[0]
416 || ent->v.absmin[1] > touch->v.absmax[1]
417 || ent->v.absmin[2] > touch->v.absmax[2]
418 || ent->v.absmax[0] < touch->v.absmin[0]
419 || ent->v.absmax[1] < touch->v.absmin[1]
420 || ent->v.absmax[2] < touch->v.absmin[2])
422 old_self = pr_global_struct->self;
423 old_other = pr_global_struct->other;
425 pr_global_struct->self = EDICT_TO_PROG(touch);
426 pr_global_struct->other = EDICT_TO_PROG(ent);
427 pr_global_struct->time = sv.time;
428 PR_ExecuteProgram (touch->v.touch, "");
430 pr_global_struct->self = old_self;
431 pr_global_struct->other = old_other;
434 // recurse down both sides
435 if (node->axis == -1)
438 // LordHavoc: optimized recursion
439 // if (ent->v.absmax[node->axis] > node->dist) SV_TouchLinks (ent, node->children[0]);
440 // if (ent->v.absmin[node->axis] < node->dist) SV_TouchLinks (ent, node->children[1]);
441 if (ent->v.absmax[node->axis] > node->dist)
443 if (ent->v.absmin[node->axis] < node->dist)
444 SV_TouchLinks(ent, node->children[1]); // order reversed to reduce code
445 node = node->children[0];
450 if (ent->v.absmin[node->axis] < node->dist)
452 node = node->children[1];
465 void SV_LinkEdict (edict_t *ent, qboolean touch_triggers)
471 SV_UnlinkEdict (ent); // unlink from old position
473 if (ent == sv.edicts)
474 return; // don't add the world
482 // LordHavoc: enabling rotating bmodels
483 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
485 // expand for rotation
489 max = DotProduct(ent->v.mins, ent->v.mins);
490 v = DotProduct(ent->v.maxs, ent->v.maxs);
497 for (i=0 ; i<3 ; i++)
499 v = fabs(ent->v.mins[i]);
502 v = fabs(ent->v.maxs[i]);
508 for (i=0 ; i<3 ; i++)
510 ent->v.absmin[i] = ent->v.origin[i] - max;
511 ent->v.absmax[i] = ent->v.origin[i] + max;
516 VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
517 VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
521 if (ent->v.solid == SOLID_BSP)
523 if (ent->v.modelindex < 0 || ent->v.modelindex > MAX_MODELS)
524 PR_RunError("SOLID_BSP with invalid modelindex!\n");
525 model = sv.models[(int) ent->v.modelindex];
528 if (model->type != mod_brush)
529 PR_RunError("SOLID_BSP with non-BSP model\n");
531 if (ent->v.angles[0] || ent->v.angles[2] || ent->v.avelocity[0] || ent->v.avelocity[2])
533 VectorAdd(ent->v.origin, model->rotatedmins, ent->v.absmin);
534 VectorAdd(ent->v.origin, model->rotatedmaxs, ent->v.absmax);
536 else if (ent->v.angles[1] || ent->v.avelocity[1])
538 VectorAdd(ent->v.origin, model->yawmins, ent->v.absmin);
539 VectorAdd(ent->v.origin, model->yawmaxs, ent->v.absmax);
543 VectorAdd(ent->v.origin, model->normalmins, ent->v.absmin);
544 VectorAdd(ent->v.origin, model->normalmaxs, ent->v.absmax);
549 // SOLID_BSP with no model is valid, mainly because some QC setup code does so temporarily
550 VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
551 VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
556 VectorAdd (ent->v.origin, ent->v.mins, ent->v.absmin);
557 VectorAdd (ent->v.origin, ent->v.maxs, ent->v.absmax);
561 // to make items easier to pick up and allow them to be grabbed off
562 // of shelves, the abs sizes are expanded
564 if ((int)ent->v.flags & FL_ITEM)
566 ent->v.absmin[0] -= 15;
567 ent->v.absmin[1] -= 15;
568 ent->v.absmin[2] -= 1;
569 ent->v.absmax[0] += 15;
570 ent->v.absmax[1] += 15;
571 ent->v.absmax[2] += 1;
575 // because movement is clipped an epsilon away from an actual edge,
576 // we must fully check even when bounding boxes don't quite touch
577 ent->v.absmin[0] -= 1;
578 ent->v.absmin[1] -= 1;
579 ent->v.absmin[2] -= 1;
580 ent->v.absmax[0] += 1;
581 ent->v.absmax[1] += 1;
582 ent->v.absmax[2] += 1;
585 if (ent->v.solid == SOLID_NOT)
588 // find the first node that the ent's box crosses
592 if (node->axis == -1)
594 if (ent->v.absmin[node->axis] > node->dist)
595 node = node->children[0];
596 else if (ent->v.absmax[node->axis] < node->dist)
597 node = node->children[1];
599 break; // crosses the node
604 if (ent->v.solid == SOLID_TRIGGER)
605 InsertLinkBefore (&ent->area, &node->trigger_edicts);
607 InsertLinkBefore (&ent->area, &node->solid_edicts);
609 // if touch_triggers, touch all entities at this node and descend for more
611 SV_TouchLinks ( ent, sv_areanodes );
617 ===============================================================================
619 POINT TESTING IN HULLS
621 ===============================================================================
630 int SV_HullPointContents (hull_t *hull, int num, vec3_t p)
633 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];
640 SV_TestEntityPosition
642 This could be a lot more efficient...
645 edict_t *SV_TestEntityPosition (edict_t *ent)
649 trace = SV_Move (ent->v.origin, ent->v.mins, ent->v.maxs, ent->v.origin, MOVE_NORMAL, ent);
651 if (trace.startsolid)
659 ===============================================================================
661 LINE TESTING IN HULLS
663 ===============================================================================
666 // 1/32 epsilon to keep floating point happy
667 #define DIST_EPSILON (0.03125)
669 #define HULLCHECKSTATE_EMPTY 0
670 #define HULLCHECKSTATE_SOLID 1
671 #define HULLCHECKSTATE_DONE 2
673 // LordHavoc: FIXME: this is not thread safe, if threading matters here, pass
674 // this as a struct to RecursiveHullCheck, RecursiveHullCheck_Impact, etc...
675 RecursiveHullCheckTraceInfo_t RecursiveHullCheckInfo;
676 #define RHC RecursiveHullCheckInfo
678 void SV_RecursiveHullCheck_Impact (mplane_t *plane, int side)
680 // LordHavoc: using doubles for extra accuracy
683 // LordHavoc: now that we have found the impact, recalculate the impact
684 // point from scratch for maximum accuracy, with an epsilon bias on the
689 frac -= DIST_EPSILON;
690 VectorNegate (plane->normal, RHC.trace->plane.normal);
691 RHC.trace->plane.dist = -plane->dist;
695 frac += DIST_EPSILON;
696 VectorCopy (plane->normal, RHC.trace->plane.normal);
697 RHC.trace->plane.dist = plane->dist;
702 t1 = RHC.start[plane->type] - frac;
703 t2 = RHC.start[plane->type] + RHC.dist[plane->type] - frac;
707 t1 = plane->normal[0] * RHC.start[0] + plane->normal[1] * RHC.start[1] + plane->normal[2] * RHC.start[2] - frac;
708 t2 = plane->normal[0] * (RHC.start[0] + RHC.dist[0]) + plane->normal[1] * (RHC.start[1] + RHC.dist[1]) + plane->normal[2] * (RHC.start[2] + RHC.dist[2]) - frac;
711 frac = t1 / (t1 - t2);
712 frac = bound(0.0f, frac, 1.0);
714 RHC.trace->fraction = frac;
715 RHC.trace->endpos[0] = RHC.start[0] + frac * RHC.dist[0];
716 RHC.trace->endpos[1] = RHC.start[1] + frac * RHC.dist[1];
717 RHC.trace->endpos[2] = RHC.start[2] + frac * RHC.dist[2];
720 int SV_RecursiveHullCheck (int num, double p1f, double p2f, double p1[3], double p2[3])
725 // LordHavoc: FIXME: this is not thread safe... if threading matters here,
726 // remove the static prefixes
728 static mplane_t *plane;
729 static double t1, t2, frac;
731 // LordHavoc: a goto! everyone flee in terror... :)
736 RHC.trace->endcontents = num;
737 if (RHC.trace->startcontents)
739 if (num == RHC.trace->startcontents)
740 RHC.trace->allsolid = false;
743 // if the first leaf is solid, set startsolid
744 if (RHC.trace->allsolid)
745 RHC.trace->startsolid = true;
746 return HULLCHECKSTATE_SOLID;
748 return HULLCHECKSTATE_EMPTY;
752 if (num != CONTENTS_SOLID)
754 RHC.trace->allsolid = false;
755 if (num == CONTENTS_EMPTY)
756 RHC.trace->inopen = true;
758 RHC.trace->inwater = true;
762 // if the first leaf is solid, set startsolid
763 if (RHC.trace->allsolid)
764 RHC.trace->startsolid = true;
765 return HULLCHECKSTATE_SOLID;
767 return HULLCHECKSTATE_EMPTY;
771 // find the point distances
772 node = RHC.hull->clipnodes + num;
774 plane = RHC.hull->planes + node->planenum;
777 t1 = p1[plane->type] - plane->dist;
778 t2 = p2[plane->type] - plane->dist;
782 t1 = DotProduct (plane->normal, p1) - plane->dist;
783 t2 = DotProduct (plane->normal, p2) - plane->dist;
786 // LordHavoc: rearranged the side/frac code
791 num = node->children[0];
794 // put the crosspoint DIST_EPSILON pixels on the near side
801 num = node->children[1];
804 // put the crosspoint DIST_EPSILON pixels on the near side
808 frac = t1 / (t1 - t2);
809 frac = bound(0.0f, frac, 1.0);
811 midf = p1f + ((p2f - p1f) * frac);
812 mid[0] = RHC.start[0] + midf * RHC.dist[0];
813 mid[1] = RHC.start[1] + midf * RHC.dist[1];
814 mid[2] = RHC.start[2] + midf * RHC.dist[2];
817 ret = SV_RecursiveHullCheck (node->children[side], p1f, midf, p1, mid);
818 if (ret != HULLCHECKSTATE_EMPTY)
819 return ret; // solid or done
820 ret = SV_RecursiveHullCheck (node->children[!side], midf, p2f, mid, p2);
821 if (ret != HULLCHECKSTATE_SOLID)
822 return ret; // empty or done
824 // front is air and back is solid, this is the impact point...
825 SV_RecursiveHullCheck_Impact(RHC.hull->planes + node->planenum, side);
827 return HULLCHECKSTATE_DONE;
834 Handles selection or creation of a clipping hull, and offseting (and
835 eventually rotation) of the end points
838 trace_t SV_ClipMoveToEntity (edict_t *ent, vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end)
841 vec3_t offset, forward, left, up;
842 double startd[3], endd[3], tempd[3];
845 // fill in a default trace
846 memset (&trace, 0, sizeof(trace_t));
848 trace.allsolid = true;
850 // get the clipping hull
851 hull = SV_HullForEntity (ent, mins, maxs, offset);
853 VectorSubtract(start, offset, startd);
854 VectorSubtract(end, offset, endd);
856 // rotate start and end into the model's frame of reference
857 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
859 AngleVectorsFLU (ent->v.angles, forward, left, up);
860 VectorCopy(startd, tempd);
861 startd[0] = DotProduct (tempd, forward);
862 startd[1] = DotProduct (tempd, left);
863 startd[2] = DotProduct (tempd, up);
864 VectorCopy(endd, tempd);
865 endd[0] = DotProduct (tempd, forward);
866 endd[1] = DotProduct (tempd, left);
867 endd[2] = DotProduct (tempd, up);
870 VectorCopy(end, trace.endpos);
872 // trace a line through the appropriate clipping hull
873 VectorCopy(startd, RecursiveHullCheckInfo.start);
874 VectorSubtract(endd, startd, RecursiveHullCheckInfo.dist);
875 RecursiveHullCheckInfo.hull = hull;
876 RecursiveHullCheckInfo.trace = &trace;
877 SV_RecursiveHullCheck (hull->firstclipnode, 0, 1, startd, endd);
879 // if we hit, unrotate endpos and normal, and store the entity we hit
880 if (trace.fraction != 1)
882 // rotate endpos back to world frame of reference
883 if (ent->v.solid == SOLID_BSP && (ent->v.angles[0] || ent->v.angles[1] || ent->v.angles[2]))
885 VectorNegate (ent->v.angles, offset);
886 AngleVectorsFLU (offset, forward, left, up);
888 VectorCopy (trace.endpos, tempd);
889 trace.endpos[0] = DotProduct (tempd, forward);
890 trace.endpos[1] = DotProduct (tempd, left);
891 trace.endpos[2] = DotProduct (tempd, up);
893 VectorCopy (trace.plane.normal, tempd);
894 trace.plane.normal[0] = DotProduct (tempd, forward);
895 trace.plane.normal[1] = DotProduct (tempd, left);
896 trace.plane.normal[2] = DotProduct (tempd, up);
899 VectorAdd (trace.endpos, offset, trace.endpos);
902 else if (trace.allsolid || trace.startsolid)
908 //===========================================================================
914 Mins and maxs enclose the entire area swept by the move
917 void SV_ClipToLinks ( areanode_t *node, moveclip_t *clip )
924 if (clip->trace.allsolid)
926 // touch linked edicts
927 for (l = node->solid_edicts.next ; l != &node->solid_edicts ; l = next)
930 touch = EDICT_FROM_AREA(l);
931 if (touch->v.solid == SOLID_NOT)
933 if (touch == clip->passedict)
935 if (touch->v.solid == SOLID_TRIGGER)
936 Host_Error ("Trigger in clipping list");
938 if (clip->type == MOVE_NOMONSTERS && touch->v.solid != SOLID_BSP)
941 if (clip->boxmins[0] > touch->v.absmax[0]
942 || clip->boxmaxs[0] < touch->v.absmin[0]
943 || clip->boxmins[1] > touch->v.absmax[1]
944 || clip->boxmaxs[1] < touch->v.absmin[1]
945 || clip->boxmins[2] > touch->v.absmax[2]
946 || clip->boxmaxs[2] < touch->v.absmin[2])
951 if (clip->passedict->v.size[0] && !touch->v.size[0])
952 continue; // points never interact
953 if (PROG_TO_EDICT(touch->v.owner) == clip->passedict)
954 continue; // don't clip against own missiles
955 if (PROG_TO_EDICT(clip->passedict->v.owner) == touch)
956 continue; // don't clip against owner
957 // LordHavoc: corpse code
958 if (clip->passedict->v.solid == SOLID_CORPSE && (touch->v.solid == SOLID_SLIDEBOX || touch->v.solid == SOLID_CORPSE))
960 if (clip->passedict->v.solid == SOLID_SLIDEBOX && touch->v.solid == SOLID_CORPSE)
964 // might interact, so do an exact clip
965 if ((int)touch->v.flags & FL_MONSTER)
966 trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins2, clip->maxs2, clip->end);
967 else if (touch->v.solid == SOLID_BSP)
968 trace = SV_ClipMoveToEntity (touch, clip->start, clip->hullmins, clip->hullmaxs, clip->end);
970 trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins, clip->maxs, clip->end);
971 // LordHavoc: take the 'best' answers from the new trace and combine with existing data
973 clip->trace.allsolid = true;
974 if (trace.startsolid)
976 clip->trace.startsolid = true;
977 if (!clip->trace.ent)
978 clip->trace.ent = trace.ent;
981 clip->trace.inopen = true;
983 clip->trace.inwater = true;
984 if (trace.fraction < clip->trace.fraction)
986 clip->trace.fraction = trace.fraction;
987 VectorCopy(trace.endpos, clip->trace.endpos);
988 clip->trace.plane = trace.plane;
989 clip->trace.endcontents = trace.endcontents;
990 clip->trace.ent = trace.ent;
998 if (trace.startsolid || trace.fraction < clip->trace.fraction)
1000 if (clip->trace.startsolid)
1002 clip->trace = trace;
1003 clip->trace.startsolid = true;
1006 clip->trace = trace;
1011 // recurse down both sides
1012 if (node->axis == -1)
1015 // LordHavoc: optimized recursion
1016 // if (clip->boxmaxs[node->axis] > node->dist) SV_ClipToLinks(node->children[0], clip);
1017 // if (clip->boxmins[node->axis] < node->dist) SV_ClipToLinks(node->children[1], clip);
1018 if (clip->boxmaxs[node->axis] > node->dist)
1020 if (clip->boxmins[node->axis] < node->dist)
1021 SV_ClipToLinks(node->children[1], clip);
1022 node = node->children[0];
1025 else if (clip->boxmins[node->axis] < node->dist)
1027 node = node->children[1];
1038 void SV_MoveBounds (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, vec3_t boxmins, vec3_t boxmaxs)
1041 // debug to test against everything
1042 boxmins[0] = boxmins[1] = boxmins[2] = -999999999;
1043 boxmaxs[0] = boxmaxs[1] = boxmaxs[2] = 999999999;
1047 for (i=0 ; i<3 ; i++)
1049 if (end[i] > start[i])
1051 boxmins[i] = start[i] + mins[i] - 1;
1052 boxmaxs[i] = end[i] + maxs[i] + 1;
1056 boxmins[i] = end[i] + mins[i] - 1;
1057 boxmaxs[i] = start[i] + maxs[i] + 1;
1068 trace_t SV_Move (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict)
1071 vec3_t bigmins, bigmaxs;
1074 memset ( &clip, 0, sizeof ( moveclip_t ) );
1076 VectorCopy(start, clip.start);
1077 VectorCopy(end, clip.end);
1078 VectorCopy(mins, clip.mins);
1079 VectorCopy(maxs, clip.maxs);
1081 clip.passedict = passedict;
1083 SV_RoundUpToHullSize(clip.mins, clip.maxs, clip.hullmins, clip.hullmaxs);
1085 if (type == MOVE_MISSILE)
1087 // LordHavoc: modified this, was = -15, now = clip.mins[i] - 15
1088 for (i=0 ; i<3 ; i++)
1090 clip.mins2[i] = clip.mins[i] - 15;
1091 clip.maxs2[i] = clip.maxs[i] + 15;
1096 VectorCopy (clip.mins, clip.mins2);
1097 VectorCopy (clip.maxs, clip.maxs2);
1100 bigmins[0] = min(clip.mins2[0], clip.hullmins[0]);
1101 bigmaxs[0] = max(clip.maxs2[0], clip.hullmaxs[0]);
1102 bigmins[1] = min(clip.mins2[1], clip.hullmins[1]);
1103 bigmaxs[1] = max(clip.maxs2[1], clip.hullmaxs[1]);
1104 bigmins[2] = min(clip.mins2[2], clip.hullmins[2]);
1105 bigmaxs[2] = max(clip.maxs2[2], clip.hullmaxs[2]);
1108 clip.trace = SV_ClipMoveToEntity (sv.edicts, start, mins, maxs, end);
1111 //if (!clip.trace.allsolid)
1113 // create the bounding box of the entire move
1114 SV_MoveBounds ( start, bigmins, bigmaxs, end, clip.boxmins, clip.boxmaxs );
1116 SV_ClipToLinks ( sv_areanodes, &clip );