• Create Account

## Quake 3 BSP CM_TraceThroughBrush

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

No replies to this topic

### #1polyfrag  Members

2468
Like
0Likes
Like

Posted 07 December 2012 - 10:52 PM

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

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;
}
} else { // leave
f = (d1+SURFACE_CLIP_EPSILON) / (d1-d2);
if ( f > 1 ) {
f = 1;
}
if (f < leaveFrac) {
leaveFrac = f;
}
}
}


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, 07 December 2012 - 10:52 PM.

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.