Add support for ellipsoids.

Not that boxes work yet, but the fix is the same.
This commit is contained in:
Bill Currie 2011-10-06 20:09:10 +09:00
parent b4da9241f6
commit 03abb3b27d
5 changed files with 35 additions and 14 deletions

View file

@ -39,13 +39,19 @@ typedef struct
vec_t dist; vec_t dist;
} plane_t; } plane_t;
typedef enum {
tr_point,
tr_box,
tr_ellipsoid,
} trace_e;
typedef struct trace_s { typedef struct trace_s {
qboolean allsolid; // if true, plane is not valid qboolean allsolid; // if true, plane is not valid
qboolean startsolid; // if true, the initial point was in a solid area qboolean startsolid; // if true, the initial point was in a solid area
qboolean inopen, inwater; qboolean inopen, inwater;
float fraction; // time completed, 1.0 = didn't hit anything float fraction; // time completed, 1.0 = didn't hit anything
vec3_t extents; // 1/2 size of traced box 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 vec3_t endpos; // final position
plane_t plane; // surface normal at impact plane_t plane; // surface normal at impact
struct edict_s *ent; // entity the surface is on struct edict_s *ent; // entity the surface is on

View file

@ -228,7 +228,7 @@ do_trace (box_t *box, hull_t *hull, vec3_t start, vec3_t end)
trace.inwater = false; trace.inwater = false;
trace.fraction = 1; trace.fraction = 1;
VectorCopy (box->extents, trace.extents); VectorCopy (box->extents, trace.extents);
trace.isbox = true; trace.type = tr_box;
VectorCopy (end, trace.endpos); VectorCopy (end, trace.endpos);
MOD_TraceLine (hull, 0, start, end, &trace); MOD_TraceLine (hull, 0, start, end, &trace);
return trace; return trace;

View file

@ -64,15 +64,28 @@ typedef struct {
static inline float static inline float
calc_offset (trace_t *trace, mplane_t *plane) calc_offset (trace_t *trace, mplane_t *plane)
{ {
if (trace->isbox) { vec_t d = 0;
vec3_t Rn;
switch (trace->type) {
case tr_point:
break;
case tr_box:
if (plane->type < 3) if (plane->type < 3)
return trace->extents[plane->type]; d = trace->extents[plane->type];
else else
return (fabs (trace->extents[0] * plane->normal[0]) d = (fabs (trace->extents[0] * plane->normal[0])
+ fabs (trace->extents[1] * plane->normal[1]) + fabs (trace->extents[1] * plane->normal[1])
+ fabs (trace->extents[2] * plane->normal[2])); + 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 static inline void

View file

@ -614,12 +614,13 @@ SV_ClipMoveToEntity (edict_t *touched, const vec3_t start,
trace.fraction = 1; trace.fraction = 1;
trace.allsolid = true; trace.allsolid = true;
trace.isbox = 0; trace.type = tr_point;
VectorCopy (end, trace.endpos); VectorCopy (end, trace.endpos);
// get the clipping hull // get the clipping hull
hull = SV_HullForEntity (touched, mins, maxs, 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 (start, offset, start_l);
VectorSubtract (end, offset, end_l); VectorSubtract (end, offset, end_l);

View file

@ -614,12 +614,13 @@ SV_ClipMoveToEntity (edict_t *touched, const vec3_t start,
trace.fraction = 1; trace.fraction = 1;
trace.allsolid = true; trace.allsolid = true;
trace.isbox = 0; trace.type = tr_point;
VectorCopy (end, trace.endpos); VectorCopy (end, trace.endpos);
// get the clipping hull // get the clipping hull
hull = SV_HullForEntity (touched, mins, maxs, 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 (start, offset, start_l);
VectorSubtract (end, offset, end_l); VectorSubtract (end, offset, end_l);