]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - chase.c
rewrote memory system entirely (hunk, cache, and zone are gone, memory pools replaced...
[xonotic/darkplaces.git] / chase.c
diff --git a/chase.c b/chase.c
index 1831a98caca4df5f0c1594a4bfa7e531375e9f3e..1b6e78ed2bb57337b5d653ed31938fcc49d33597 100644 (file)
--- a/chase.c
+++ b/chase.c
@@ -8,7 +8,7 @@ of the License, or (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 
 See the GNU General Public License for more details.
 
@@ -21,9 +21,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 #include "quakedef.h"
 
-cvar_t chase_back = {"chase_back", "48"};
-cvar_t chase_up = {"chase_up", "22"};
-cvar_t chase_active = {"chase_active", "0"};
+cvar_t chase_back = {CVAR_SAVE, "chase_back", "48"};
+cvar_t chase_up = {CVAR_SAVE, "chase_up", "48"};
+cvar_t chase_active = {CVAR_SAVE, "chase_active", "0"};
 
 void Chase_Init (void)
 {
@@ -38,44 +38,53 @@ void Chase_Reset (void)
 //     start position 12 units behind head
 }
 
-qboolean SV_RecursiveHullCheck (hull_t *hull, int num, float p1f, float p2f, vec3_t p1, vec3_t p2, trace_t *trace);
+int traceline_endcontents;
 
-void TraceLine (vec3_t start, vec3_t end, vec3_t impact)
+float TraceLine (vec3_t start, vec3_t end, vec3_t impact, vec3_t normal, int contents)
 {
-       trace_t trace;
+       trace_t trace;
 
-       memset (&trace, 0, sizeof(trace));
-       SV_RecursiveHullCheck (cl.worldmodel->hulls, 0, 0, 1, start, end, &trace);
+// FIXME: broken, fix it
+//     if (impact == NULL && normal == NULL && contents == 0)
+//             return SV_TestLine (cl.worldmodel->hulls, 0, start, end);
 
-       if (trace.fraction < 1)
-       {
+       Mod_CheckLoaded(cl.worldmodel);
+       memset (&trace, 0, sizeof(trace));
+       VectorCopy (end, trace.endpos);
+       trace.fraction = 1;
+       trace.startcontents = contents;
+       VectorCopy(start, RecursiveHullCheckInfo.start);
+       VectorSubtract(end, start, RecursiveHullCheckInfo.dist);
+       RecursiveHullCheckInfo.hull = cl.worldmodel->hulls;
+       RecursiveHullCheckInfo.trace = &trace;
+       SV_RecursiveHullCheck (0, 0, 1, start, end);
+       if (impact)
                VectorCopy (trace.endpos, impact);
-       }
-       else
-       {
-               VectorCopy (end, impact);
-       }
+       if (normal)
+               VectorCopy (trace.plane.normal, normal);
+       traceline_endcontents = trace.endcontents;
+       return trace.fraction;
 }
 
 void Chase_Update (void)
 {
-       vec3_t  forward, up, right, stop, chase_dest;
+       vec3_t  forward, stop, chase_dest, normal;
        float   dist;
 
        chase_back.value = bound(0, chase_back.value, 128);
-       chase_up.value = bound(-64, chase_up.value, 64);
+       chase_up.value = bound(-48, chase_up.value, 96);
 
-       AngleVectors (cl.viewangles, forward, right, up);
+       AngleVectors (cl.viewangles, forward, NULL, NULL);
 
        dist = -chase_back.value - 8;
        chase_dest[0] = r_refdef.vieworg[0] + forward[0] * dist;
        chase_dest[1] = r_refdef.vieworg[1] + forward[1] * dist;
        chase_dest[2] = r_refdef.vieworg[2] + forward[2] * dist + chase_up.value;
 
-       TraceLine (r_refdef.vieworg, chase_dest, stop);
-       chase_dest[0] = stop[0] + forward[0] * 8;
-       chase_dest[1] = stop[1] + forward[1] * 8;
-       chase_dest[2] = stop[2] + forward[2] * 8;
+       TraceLine (r_refdef.vieworg, chase_dest, stop, normal, 0);
+       chase_dest[0] = stop[0] + forward[0] * 8 + normal[0] * 4;
+       chase_dest[1] = stop[1] + forward[1] * 8 + normal[1] * 4;
+       chase_dest[2] = stop[2] + forward[2] * 8 + normal[2] * 4;
 
        VectorCopy (chase_dest, r_refdef.vieworg);
 }