Now I feel stupid. The following patch is probably a much better way to do it. Please test.
Index: code/model/modelcollide.cpp
===================================================================
--- code/model/modelcollide.cpp (revision 9771)
+++ code/model/modelcollide.cpp (working copy)
@@ -76,7 +76,7 @@
// Returns non-zero if vector from p0 to pdir
// intersects the bounding box.
// hitpos could be NULL, so don't fill it if it is.
-int mc_ray_boundingbox( vec3d *min, vec3d *max, vec3d * p0, vec3d *pdir, vec3d *hitpos )
+inline int mc_ray_boundingbox( vec3d *min, vec3d *max, vec3d * p0, vec3d *pdir, vec3d *hitpos )
{
vec3d tmp_hitpos;
@@ -481,7 +481,7 @@
int model_collide_sub( void *model_ptr );
-void model_collide_sortnorm(ubyte * p)
+inline void model_collide_sortnorm(ubyte * p)
{
int frontlist = w(p+36);
int backlist = w(p+40);
@@ -509,7 +509,7 @@
//calls the object interpreter to render an object. The object renderer
//is really a seperate pipeline. returns true if drew
-int model_collide_sub(void *model_ptr )
+inline int model_collide_sub(void *model_ptr )
{
ubyte *p = (ubyte *)model_ptr;
int chunk_type, chunk_size;
@@ -602,7 +602,7 @@
}
}
-void model_collide_bsp(bsp_collision_tree *tree, int node_index)
+inline void model_collide_bsp(bsp_collision_tree *tree, int node_index)
{
if ( tree->node_list == NULL || tree->n_verts <= 0) {
return;
@@ -949,7 +949,7 @@
return false;
}
-bool mc_check_sldc(int offset)
+inline bool mc_check_sldc(int offset)
{
if (offset > Mc_pm->sldc_size-5) //no way is this big enough
return false;
@@ -999,7 +999,7 @@
}
// checks a vector collision against a ships shield (if it has shield points defined).
-void mc_check_shield()
+inline void mc_check_shield()
{
int i;
@@ -1031,7 +1031,7 @@
// This function recursively checks a submodel and its children
// for a collision with a vector.
-void mc_check_subobj( int mn )
+inline void mc_check_subobj( int mn )
{
vec3d tempv;
vec3d hitpt; // used in bounding box check
Index: code/math/fvi.cpp
===================================================================
--- code/math/fvi.cpp (revision 9771)
+++ code/math/fvi.cpp (working copy)
@@ -314,75 +314,75 @@
return 0;
}
-/**
- * Finds intersection of a ray and an axis-aligned bounding box
- *
- * Given a ray with origin at p0, and direction pdir, this function
- * returns non-zero if that ray intersects an axis-aligned bounding box
- * from min to max. If there was an intersection, then hitpt will contain
- * the point where the ray begins inside the box.
- * Fast ray-box intersection taken from Graphics Gems I, pages 395,736.
- */
-int fvi_ray_boundingbox( vec3d *min, vec3d *max, vec3d * p0, vec3d *pdir, vec3d *hitpt )
-{
- bool inside = true;
- bool middle[3] = { true, true, true };
- int i;
- int which_plane;
- float maxt[3];
- float candidate_plane[3];
+///**
+// * Finds intersection of a ray and an axis-aligned bounding box
+// *
+// * Given a ray with origin at p0, and direction pdir, this function
+// * returns non-zero if that ray intersects an axis-aligned bounding box
+// * from min to max. If there was an intersection, then hitpt will contain
+// * the point where the ray begins inside the box.
+// * Fast ray-box intersection taken from Graphics Gems I, pages 395,736.
+// */
+//int fvi_ray_boundingbox( vec3d *min, vec3d *max, vec3d * p0, vec3d *pdir, vec3d *hitpt )
+//{
+// bool inside = true;
+// bool middle[3] = { true, true, true };
+// int i;
+// int which_plane;
+// float maxt[3];
+// float candidate_plane[3];
+//
+// for (i = 0; i < 3; i++) {
+// if (p0->a1d[i] < min->a1d[i]) {
+// candidate_plane[i] = min->a1d[i];
+// middle[i] = false;
+// inside = false;
+// } else if (p0->a1d[i] > max->a1d[i]) {
+// candidate_plane[i] = max->a1d[i];
+// middle[i] = false;
+// inside = false;
+// }
+// }
+//
+// // ray origin inside bounding box
+// if ( inside ) {
+// *hitpt = *p0;
+// return 1;
+// }
+//
+// // calculate T distances to candidate plane
+// for (i = 0; i < 3; i++) {
+// if ( !middle[i] && (pdir->a1d[i] != 0.0f) )
+// maxt[i] = (candidate_plane[i] - p0->a1d[i]) / pdir->a1d[i];
+// else
+// maxt[i] = -1.0f;
+// }
+//
+// // Get largest of the maxt's for final choice of intersection
+// which_plane = 0;
+// for (i = 1; i < 3; i++) {
+// if (maxt[which_plane] < maxt[i])
+// which_plane = i;
+// }
+//
+// // check final candidate actually inside box
+// if (maxt[which_plane] < 0.0f)
+// return 0;
+//
+// for (i = 0; i < 3; i++) {
+// if (which_plane != i) {
+// hitpt->a1d[i] = p0->a1d[i] + maxt[which_plane] * pdir->a1d[i];
+//
+// if ( (hitpt->a1d[i] < min->a1d[i]) || (hitpt->a1d[i] > max->a1d[i]) )
+// return 0;
+// } else {
+// hitpt->a1d[i] = candidate_plane[i];
+// }
+// }
+//
+// return 1;
+//}
- for (i = 0; i < 3; i++) {
- if (p0->a1d[i] < min->a1d[i]) {
- candidate_plane[i] = min->a1d[i];
- middle[i] = false;
- inside = false;
- } else if (p0->a1d[i] > max->a1d[i]) {
- candidate_plane[i] = max->a1d[i];
- middle[i] = false;
- inside = false;
- }
- }
-
- // ray origin inside bounding box
- if ( inside ) {
- *hitpt = *p0;
- return 1;
- }
-
- // calculate T distances to candidate plane
- for (i = 0; i < 3; i++) {
- if ( !middle[i] && (pdir->a1d[i] != 0.0f) )
- maxt[i] = (candidate_plane[i] - p0->a1d[i]) / pdir->a1d[i];
- else
- maxt[i] = -1.0f;
- }
-
- // Get largest of the maxt's for final choice of intersection
- which_plane = 0;
- for (i = 1; i < 3; i++) {
- if (maxt[which_plane] < maxt[i])
- which_plane = i;
- }
-
- // check final candidate actually inside box
- if (maxt[which_plane] < 0.0f)
- return 0;
-
- for (i = 0; i < 3; i++) {
- if (which_plane != i) {
- hitpt->a1d[i] = p0->a1d[i] + maxt[which_plane] * pdir->a1d[i];
-
- if ( (hitpt->a1d[i] < min->a1d[i]) || (hitpt->a1d[i] > max->a1d[i]) )
- return 0;
- } else {
- hitpt->a1d[i] = candidate_plane[i];
- }
- }
-
- return 1;
-}
-
/**
* Given largest componant of normal, return i & j
* If largest componant is negative, swap i & j
Index: code/math/fvi.h
===================================================================
--- code/math/fvi.h (revision 9771)
+++ code/math/fvi.h (working copy)
@@ -104,8 +104,77 @@
// from min to max. If there was an intersection, then hitpt will contain
// the point where the ray begins inside the box.
// Fast ray-box intersection taken from Graphics Gems I, pages 395,736.
-int fvi_ray_boundingbox( vec3d *min, vec3d *max, vec3d * p0, vec3d *pdir, vec3d *hitpt );
+//int fvi_ray_boundingbox( vec3d *min, vec3d *max, vec3d * p0, vec3d *pdir, vec3d *hitpt );
+/**
+ * Finds intersection of a ray and an axis-aligned bounding box
+ *
+ * Given a ray with origin at p0, and direction pdir, this function
+ * returns non-zero if that ray intersects an axis-aligned bounding box
+ * from min to max. If there was an intersection, then hitpt will contain
+ * the point where the ray begins inside the box.
+ * Fast ray-box intersection taken from Graphics Gems I, pages 395,736.
+ */
+inline int fvi_ray_boundingbox( vec3d *min, vec3d *max, vec3d * p0, vec3d *pdir, vec3d *hitpt )
+{
+ bool inside = true;
+ bool middle[3] = { true, true, true };
+ int i;
+ int which_plane;
+ float maxt[3];
+ float candidate_plane[3];
+
+ for (i = 0; i < 3; i++) {
+ if (p0->a1d[i] < min->a1d[i]) {
+ candidate_plane[i] = min->a1d[i];
+ middle[i] = false;
+ inside = false;
+ } else if (p0->a1d[i] > max->a1d[i]) {
+ candidate_plane[i] = max->a1d[i];
+ middle[i] = false;
+ inside = false;
+ }
+ }
+
+ // ray origin inside bounding box
+ if ( inside ) {
+ *hitpt = *p0;
+ return 1;
+ }
+
+ // calculate T distances to candidate plane
+ for (i = 0; i < 3; i++) {
+ if ( !middle[i] && (pdir->a1d[i] != 0.0f) )
+ maxt[i] = (candidate_plane[i] - p0->a1d[i]) / pdir->a1d[i];
+ else
+ maxt[i] = -1.0f;
+ }
+
+ // Get largest of the maxt's for final choice of intersection
+ which_plane = 0;
+ for (i = 1; i < 3; i++) {
+ if (maxt[which_plane] < maxt[i])
+ which_plane = i;
+ }
+
+ // check final candidate actually inside box
+ if (maxt[which_plane] < 0.0f)
+ return 0;
+
+ for (i = 0; i < 3; i++) {
+ if (which_plane != i) {
+ hitpt->a1d[i] = p0->a1d[i] + maxt[which_plane] * pdir->a1d[i];
+
+ if ( (hitpt->a1d[i] < min->a1d[i]) || (hitpt->a1d[i] > max->a1d[i]) )
+ return 0;
+ } else {
+ hitpt->a1d[i] = candidate_plane[i];
+ }
+ }
+
+ return 1;
+}
+
// sphere polygon collision prototypes
// Given a polygon vertex list and a moving sphere, find the first contact the sphere makes with the edge, if any