mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-10 15:22:04 +00:00
Sanitize trace_hits_plane().
While unit normals aren't needed, they were too big for sane math. Now epsilon can be used for the distance tests. One of the two new tests passes now :).
This commit is contained in:
parent
2b65f81b72
commit
8c840a7003
1 changed files with 14 additions and 1 deletions
|
@ -55,6 +55,8 @@ static __attribute__ ((used)) const char rcsid[] =
|
|||
#define DIST_EPSILON (0.03125)
|
||||
#endif
|
||||
|
||||
#define PLANE_EPSILON (0.001)
|
||||
|
||||
typedef struct {
|
||||
vec3_t start;
|
||||
vec3_t end;
|
||||
|
@ -64,6 +66,15 @@ typedef struct {
|
|||
plane_t *plane;
|
||||
} tracestack_t;
|
||||
|
||||
static void
|
||||
fast_norm (vec3_t v)
|
||||
{
|
||||
vec_t m;
|
||||
|
||||
m = fabs (v[0]) + fabs (v[1]) + fabs (v[2]);
|
||||
VectorScale (v, 1 / m, v);
|
||||
}
|
||||
|
||||
static inline float
|
||||
calc_offset (const trace_t *trace, const plane_t *plane)
|
||||
{
|
||||
|
@ -156,10 +167,12 @@ trace_hits_portal (hull_t *hull, trace_t *trace, clipport_t *portal,
|
|||
// the same normal vector, the normal vector length does not
|
||||
// matter.
|
||||
CrossProduct (vel, edge, cutplane.normal);
|
||||
fast_norm (cutplane.normal);
|
||||
cutplane.dist = DotProduct (cutplane.normal, point);
|
||||
dist = PlaneDiff (start, &cutplane);
|
||||
offset = calc_offset (trace, &cutplane);
|
||||
if ((vn > 0 && dist >= offset) || (vn < 0 && dist <= -offset))
|
||||
if ((vn > 0 && dist >= offset - PLANE_EPSILON)
|
||||
|| (vn < 0 && dist <= -offset + PLANE_EPSILON))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
|
Loading…
Reference in a new issue