diff --git a/include/world.h b/include/world.h index b9b274dd5..5744b8f71 100644 --- a/include/world.h +++ b/include/world.h @@ -39,13 +39,19 @@ typedef struct vec_t dist; } plane_t; +typedef enum { + tr_point, + tr_box, + tr_ellipsoid, +} trace_e; + typedef struct trace_s { qboolean allsolid; // if true, plane is not valid qboolean startsolid; // if true, the initial point was in a solid area qboolean inopen, inwater; float fraction; // time completed, 1.0 = didn't hit anything vec3_t extents; // 1/2 size of traced box - qboolean isbox; // box or point + trace_e type; // type of trace to perform vec3_t endpos; // final position plane_t plane; // surface normal at impact struct edict_s *ent; // entity the surface is on diff --git a/libs/models/test/testclip.c b/libs/models/test/testclip.c index d4dfd4734..ef0266073 100644 --- a/libs/models/test/testclip.c +++ b/libs/models/test/testclip.c @@ -228,7 +228,7 @@ do_trace (box_t *box, hull_t *hull, vec3_t start, vec3_t end) trace.inwater = false; trace.fraction = 1; VectorCopy (box->extents, trace.extents); - trace.isbox = true; + trace.type = tr_box; VectorCopy (end, trace.endpos); MOD_TraceLine (hull, 0, start, end, &trace); return trace; diff --git a/libs/models/trace.c b/libs/models/trace.c index ded4eab41..92e28755f 100644 --- a/libs/models/trace.c +++ b/libs/models/trace.c @@ -64,15 +64,28 @@ typedef struct { static inline float calc_offset (trace_t *trace, mplane_t *plane) { - if (trace->isbox) { - if (plane->type < 3) - return trace->extents[plane->type]; - else - return (fabs (trace->extents[0] * plane->normal[0]) - + fabs (trace->extents[1] * plane->normal[1]) - + fabs (trace->extents[2] * plane->normal[2])); + vec_t d = 0; + vec3_t Rn; + + switch (trace->type) { + case tr_point: + break; + case tr_box: + if (plane->type < 3) + d = trace->extents[plane->type]; + else + d = (fabs (trace->extents[0] * plane->normal[0]) + + fabs (trace->extents[1] * plane->normal[1]) + + fabs (trace->extents[2] * plane->normal[2])); + break; + case tr_ellipsoid: + VectorSet (trace->extents[0] * plane->normal[0], + trace->extents[1] * plane->normal[1], + trace->extents[2] * plane->normal[2], Rn); + d = sqrt(DotProduct (Rn, Rn)); //FIXME no sqrt + break; } - return 0; + return d; } static inline void diff --git a/nq/source/world.c b/nq/source/world.c index 2ae9aa700..7c49f979d 100644 --- a/nq/source/world.c +++ b/nq/source/world.c @@ -614,12 +614,13 @@ SV_ClipMoveToEntity (edict_t *touched, const vec3_t start, trace.fraction = 1; trace.allsolid = true; - trace.isbox = 0; + trace.type = tr_point; VectorCopy (end, trace.endpos); // get the clipping hull hull = SV_HullForEntity (touched, mins, maxs, - trace.isbox ? trace.extents : 0, offset); + trace.type != tr_point ? trace.extents : 0, + offset); VectorSubtract (start, offset, start_l); VectorSubtract (end, offset, end_l); diff --git a/qw/source/world.c b/qw/source/world.c index 2ae9aa700..7c49f979d 100644 --- a/qw/source/world.c +++ b/qw/source/world.c @@ -614,12 +614,13 @@ SV_ClipMoveToEntity (edict_t *touched, const vec3_t start, trace.fraction = 1; trace.allsolid = true; - trace.isbox = 0; + trace.type = tr_point; VectorCopy (end, trace.endpos); // get the clipping hull hull = SV_HullForEntity (touched, mins, maxs, - trace.isbox ? trace.extents : 0, offset); + trace.type != tr_point ? trace.extents : 0, + offset); VectorSubtract (start, offset, start_l); VectorSubtract (end, offset, end_l);