66#define AXISLEN_EPSILON2 WWMATH_EPSILON * WWMATH_EPSILON
171static bool obb_intersect_box0_basis
190 return ((u > rsum) || (u < -rsum));
209static bool obb_intersect_box1_basis
228 return ((u > rsum) || (u < -rsum));
248static inline bool obb_intersect_axis
261 return ((u > rsum) || (u < -rsum));
298 if (obb_intersect_box0_basis(context,0))
return false;
308 if (obb_intersect_box0_basis(context,1))
return false;
319 if (obb_intersect_box0_basis(context,2))
return false;
327 if (obb_intersect_box1_basis(context,0))
return false;
331 if (obb_intersect_box1_basis(context,1))
return false;
335 if (obb_intersect_box1_basis(context,2))
return false;
345 if (obb_intersect_axis(context,axis,ra,rb))
return false;
355 if (obb_intersect_axis(context,axis,ra,rb))
return false;
365 if (obb_intersect_axis(context,axis,ra,rb))
return false;
375 if (obb_intersect_axis(context,axis,ra,rb))
return false;
385 if (obb_intersect_axis(context,axis,ra,rb))
return false;
395 if (obb_intersect_axis(context,axis,ra,rb))
return false;
405 if (obb_intersect_axis(context,axis,ra,rb))
return false;
415 if (obb_intersect_axis(context,axis,ra,rb))
return false;
425 if (obb_intersect_axis(context,axis,ra,rb))
return false;
579static inline bool obb_separation_test
597 tmp = (rsum-u0)/(u1-u0);
610 tmp = (-rsum-u0)/(u1-u0);
634static bool obb_check_box0_basis
652 return obb_separation_test(context,ra,rb,u0,u1);
668static bool obb_check_box1_basis
685 return obb_separation_test(context,ra,rb,u0,u1);
701static inline bool obb_check_axis
710 return obb_separation_test(context,ra,rb,u0,u1);
726static inline void obb_compute_projections
760#pragma message("Fatal assert disabled for demo, obb-obb collision")
850static inline float eval_side(
float ab,
float side)
854 }
else if (ab < 0.0f) {
901 for (j=0; j<3; j++) {
902 y[j] = -eval_side(context.
AB[i][j],context.
Side);
912 for (i=0; i<3; i++) {
913 x[i] = eval_side(context.
AB[i][j],context.
Side);
925 den = (1.0f - context.
AB[0][0] * context.
AB[0][0]);
929 x[0] += context.
AB[0][1] * y[1] + context.
AB[0][2] * y[2];
942 den = (1.0f - context.
AB[0][1] * context.
AB[0][1]);
946 x[0] += context.
AB[0][0] * y[0] + context.
AB[0][2] * y[2];
959 den = (1.0f - context.
AB[0][2] * context.
AB[0][2]);
963 x[0] += context.
AB[0][0] * y[0] + context.
AB[0][1] * y[1];
976 den = (1.0f - context.
AB[1][0] * context.
AB[1][0]);
980 x[1] += context.
AB[1][1] * y[1] + context.
AB[1][2] * y[2];
993 den = 1.0f / (1.0f - context.
AB[1][1] * context.
AB[1][1]);
997 x[1] += context.
AB[1][0] * y[0] + context.
AB[1][2] * y[2];
1010 den = (1.0f - context.
AB[1][2] * context.
AB[1][2]);
1014 x[1] += context.
AB[1][0] * y[0] + context.
AB[1][1] * y[1];
1027 den = (1.0f - context.
AB[2][0] * context.
AB[2][0]);
1031 x[2] += context.
AB[2][1] * y[1] + context.
AB[2][2] * y[2];
1044 den = (1.0f - context.
AB[2][1] * context.
AB[2][1]);
1048 x[2] += context.
AB[2][0] * y[0] + context.
AB[2][2] * y[2];
1061 den = (1.0f - context.
AB[2][2] * context.
AB[2][2]);
1065 x[2] += context.
AB[2][0] * y[0] + context.
AB[2][1] * y[1];
1075 x[0]*context.
A[0].
X +
1076 x[1]*context.
A[1].
X +
1077 x[2]*context.
A[2].
X;
1080 x[0]*context.
A[0].
Y +
1081 x[1]*context.
A[1].
Y +
1082 x[2]*context.
A[2].
Y;
1085 x[0]*context.
A[0].
Z +
1086 x[1]*context.
A[1].
Z +
1087 x[2]*context.
A[2].
Z;
1127 if (obb_check_box0_basis(context,0))
goto exit;
1136 if (obb_check_box0_basis(context,1))
goto exit;
1145 if (obb_check_box0_basis(context,2))
goto exit;
1151 if (obb_check_box1_basis(context,0))
goto exit;
1157 if (obb_check_box1_basis(context,1))
goto exit;
1163 if (obb_check_box1_basis(context,2))
goto exit;
1182 if (obb_check_axis(context,ra,rb))
goto exit;
1193 if (obb_check_axis(context,ra,rb))
goto exit;
1204 if (obb_check_axis(context,ra,rb))
goto exit;
1215 if (obb_check_axis(context,ra,rb))
goto exit;
1226 if (obb_check_axis(context,ra,rb))
goto exit;
1237 if (obb_check_axis(context,ra,rb))
goto exit;
1248 if (obb_check_axis(context,ra,rb))
goto exit;
1259 if (obb_check_axis(context,ra,rb))
goto exit;
1270 if (obb_check_axis(context,ra,rb))
goto exit;
1283 obb_compute_projections(context,&ra,&rb);
1284 if (obb_check_axis(context,ra,rb))
goto exit;
1292 obb_compute_projections(context,&ra,&rb);
1293 if (obb_check_axis(context,ra,rb))
goto exit;
1301 obb_compute_projections(context,&ra,&rb);
1302 if (obb_check_axis(context,ra,rb))
goto exit;
1323 compute_contact_normal(context,result);
1325 compute_contact_point(context,result);
static bool Collide(const LineSegClass &line, const AAPlaneClass &plane, CastResultStruct *result)
static bool Intersection_Test(const AABoxClass &box, const TriClass &tri)
void Compute_Point(float params[3], Vector3 *set_point) const
static WWINLINE float Dot_Product(const Vector3 &a, const Vector3 &b)
WWINLINE float Length2(void) const
static WWINLINE void Subtract(const Vector3 &a, const Vector3 &b, Vector3 *c)
static WWINLINE void Add(const Vector3 &a, const Vector3 &b, Vector3 *c)
static WWINLINE void Cross_Product(const Vector3 &a, const Vector3 &b, Vector3 *result)
static WWINLINE float Fabs(float val)
bool intersect_obb_obb(ObbIntersectionStruct &context)
bool collide_obb_obb(ObbCollisionStruct &context, CastResultStruct *result)
ObbCollisionStruct(const OBBoxClass &box0, const Vector3 &move0, const OBBoxClass &box1, const Vector3 &move1)
ObbIntersectionStruct(const OBBoxClass &box0, const OBBoxClass &box1)