• Advertisement
Sign in to follow this  

Quake 3 BSP CM_TraceThroughBrush

This topic is 1869 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm fixing a problem in my own engine and can't understand something from Quake 3 in CM_TraceThroughBrush.

https://github.com/id-Software/Quake-III-Arena/blob/master/code/qcommon/cm_trace.c

[code]
for (i = 0; i < brush->numsides; i++) {
side = brush->sides + i;
plane = side->plane;
// adjust the plane distance apropriately for mins/maxs
dist = plane->dist - DotProduct( tw->offsets[ plane->signbits ], plane->normal );
d1 = DotProduct( tw->start, plane->normal ) - dist;
d2 = DotProduct( tw->end, plane->normal ) - dist;
if (d2 > 0) {
getout = qtrue; // endpoint is not in solid
}
if (d1 > 0) {
startout = qtrue;
}
// if completely in front of face, no intersection with the entire brush
if (d1 > 0 && ( d2 >= SURFACE_CLIP_EPSILON || d2 >= d1 ) ) {
return;
}
// if it doesn't cross the plane, the plane isn't relevent
if (d1 <= 0 && d2 <= 0 ) {
continue;
}
// crosses face
if (d1 > d2) { // enter
f = (d1-SURFACE_CLIP_EPSILON) / (d1-d2);
if ( f < 0 ) {
f = 0;
}
if (f > enterFrac) {
enterFrac = f;
clipplane = plane;
leadside = side;
}
} else { // leave
f = (d1+SURFACE_CLIP_EPSILON) / (d1-d2);
if ( f > 1 ) {
f = 1;
}
if (f < leaveFrac) {
leaveFrac = f;
}
}
}
[/code]

If d1 and d2 are the starting and ending distances of the box from the plane, why does d1 > d2 mean that it crosses the plane? Shouldn't it be d1*d2 < 0? Edited by polyfrag

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement