Quake2: Deficiency in Cm_TransformedBoxTrace
Posted: Mon Dec 09, 2013 4:24 pm
I noticed the other day that while Cm_TransformedBoxTrace rotates plane normals for inline BSP models, it does not adjust plane distance for them:
As you can see, rotation is handled, but the plane distance is not. I'm going to try to fix this, but I'm wondering if anyone else already has, and / or what I might break in doing so
Code: Select all
/*
* @brief Collision detection for inline BSP models. Rotates the specified end
* points into the model's space, and traces down the relevant subset of the
* BSP tree.
*/
c_trace_t Cm_TransformedBoxTrace(const vec3_t start, const vec3_t end, const vec3_t mins,
const vec3_t maxs, const int32_t head_node, const int32_t contents, const vec3_t origin,
const vec3_t angles) {
c_trace_t trace;
vec3_t start_l, end_l;
vec3_t forward, right, up;
vec3_t temp;
_Bool rotated;
// subtract origin offset
VectorSubtract(start, origin, start_l);
VectorSubtract(end, origin, end_l);
// rotate start and end into the models frame of reference
if (head_node != cm_box.head_node && (angles[0] || angles[1] || angles[2]))
rotated = true;
else
rotated = false;
if (rotated) {
AngleVectors(angles, forward, right, up);
VectorCopy(start_l, temp);
start_l[0] = DotProduct(temp, forward);
start_l[1] = -DotProduct(temp, right);
start_l[2] = DotProduct(temp, up);
VectorCopy(end_l, temp);
end_l[0] = DotProduct(temp, forward);
end_l[1] = -DotProduct(temp, right);
end_l[2] = DotProduct(temp, up);
}
// sweep the box through the model
trace = Cm_BoxTrace(start_l, end_l, mins, maxs, head_node, contents);
if (rotated && trace.fraction != 1.0) {
vec3_t a;
VectorNegate(angles, a);
AngleVectors(a, forward, right, up);
VectorCopy(trace.plane.normal, temp);
trace.plane.normal[0] = DotProduct(temp, forward);
trace.plane.normal[1] = -DotProduct(temp, right);
trace.plane.normal[2] = DotProduct(temp, up);
}
trace.end[0] = start[0] + trace.fraction * (end[0] - start[0]);
trace.end[1] = start[1] + trace.fraction * (end[1] - start[1]);
trace.end[2] = start[2] + trace.fraction * (end[2] - start[2]);
return trace;
}