@@ -369,7 +369,7 @@ static void testRotatedPointsAgainstRect(
369369 Int *avgTot,
370370 Real *minDistSqr
371371);*/
372- static Real fast_getBoundaryLength (
372+ static Real fast_hypot (
373373 Real x1,
374374 Real x2,
375375 Real y1,
@@ -456,9 +456,12 @@ static void testRotatedPointsAgainstRect(
456456 avg->y += pts->y ;
457457 *avgTot += 1 ;
458458
459- Real distanceSqr = sqr (ptx_new) + sqr (pty_new);
460- if (*minDistSqr > distanceSqr)
461- *minDistSqr = distanceSqr;
459+ if (minDistSqr)
460+ {
461+ Real distanceSqr = sqr (ptx_new) + sqr (pty_new);
462+ if (*minDistSqr > distanceSqr)
463+ *minDistSqr = distanceSqr;
464+ }
462465 }
463466 }
464467}
@@ -819,6 +822,7 @@ static Bool xy_collideTest_Rect_Circle(const CollideInfo *a, const CollideInfo *
819822 if (cinfo)
820823 {
821824 cinfo->normal = diff;
825+ flipCoord3D (&cinfo->normal );
822826 cinfo->normal .normalize ();
823827 cinfo->loc = b->position ;
824828 projectCoord3D (&cinfo->loc , &cinfo->normal , b->geom .getMajorRadius ());
@@ -841,7 +845,8 @@ static Bool xy_collideTest_Rect_Circle(const CollideInfo *a, const CollideInfo *
841845 // cinfo->distSqr = minDist > 0.0f ? sqr(minDist) : 0.0f;
842846 // cinfo->distSqr = minDistSqr;
843847 // }
844- cinfo->distSqr = sqr (distance);
848+ if (cinfo->getDistance )
849+ cinfo->distSqr = sqr (distance);
845850 }
846851 return true ;
847852 }
@@ -872,9 +877,12 @@ static Bool xy_collideTest_Circle_Circle(const CollideInfo *a, const CollideInfo
872877 cinfo->normal .normalize ();
873878 cinfo->loc = a->position ;
874879 projectCoord3D (&cinfo->loc , &cinfo->normal , a->geom .getMajorRadius ());
875- // cinfo->distSqr = sqr(sqrtf(distSqr) - b->geom.getMajorRadius()); // Formula is touchingDistSqr - b_Radius, this is the summarization
876- Real distance = sqrtf (distSqr) - b->geom .getBoundingSphereRadius ();
877- cinfo->distSqr = distance > 0 .0f ? sqr (distance) : 0 .0f ;
880+ if (cinfo->getDistance )
881+ {
882+ // cinfo->distSqr = sqr(sqrtf(distSqr) - b->geom.getMajorRadius()); // Formula is touchingDistSqr - b_Radius, this is the summarization
883+ Real distance = sqrtf (distSqr) - b->geom .getBoundingSphereRadius ();
884+ cinfo->distSqr = distance > 0 .0f ? sqr (distance) : 0 .0f ;
885+ }
878886 }
879887
880888 return true ;
@@ -894,10 +902,10 @@ static Bool xy_collideTest_Rect_Rect(const CollideInfo *a, const CollideInfo *b,
894902 Real minDistSqr = HUGE_DIST_SQR;
895903
896904 rectToFourPoints (a, pts);
897- testRotatedPointsAgainstRect (pts, b, &avg, &avgTot, &minDistSqr);
905+ testRotatedPointsAgainstRect (pts, b, &avg, &avgTot, cinfo-> getDistance ? &minDistSqr : NULL );
898906
899907 rectToFourPoints (b, pts);
900- testRotatedPointsAgainstRect (pts, a, &avg, &avgTot, &minDistSqr);
908+ testRotatedPointsAgainstRect (pts, a, &avg, &avgTot, cinfo-> getDistance ? &minDistSqr : NULL );
901909
902910 if (avgTot > 0 )
903911 {
@@ -925,7 +933,7 @@ static Bool xy_collideTest_Rect_Rect(const CollideInfo *a, const CollideInfo *b,
925933 cinfo->normal .normalize ();
926934
927935 // Get the distance for damage calculation
928- if (minDistSqr < HUGE_DIST_SQR)
936+ if (cinfo-> getDistance && minDistSqr < HUGE_DIST_SQR)
929937 {
930938 // Real minDist = sqrtf(minDistSqr);
931939 // Real boundingDistance = a->geom.getBoundingSphereRadius() - a->geom.getMajorRadius();
@@ -1058,9 +1066,12 @@ static Bool collideTest_Sphere_Sphere(const CollideInfo *a, const CollideInfo *b
10581066 cinfo->normal .normalize ();
10591067 cinfo->loc = a->position ;
10601068 projectCoord3D (&cinfo->loc , &cinfo->normal , a->geom .getMajorRadius ());
1061- // cinfo->distSqr = sqr(sqrtf(distSqr) - b->geom.getMajorRadius()); // Formula is touchingDistSqr - b_Radius, this is the summarization
1062- Real distance = sqrtf (distSqr) - b->geom .getBoundingSphereRadius ();
1063- cinfo->distSqr = distance > 0 .0f ? sqr (distance) : 0 .0f ;
1069+ if (cinfo->getDistance )
1070+ {
1071+ // cinfo->distSqr = sqr(sqrtf(distSqr) - b->geom.getMajorRadius()); // Formula is touchingDistSqr - b_Radius, this is the summarization
1072+ Real distance = sqrtf (distSqr) - b->geom .getBoundingSphereRadius ();
1073+ cinfo->distSqr = distance > 0 .0f ? sqr (distance) : 0 .0f ;
1074+ }
10641075 }
10651076
10661077 return true ;
@@ -2378,11 +2389,21 @@ Bool PartitionManager::geomCollidesWithGeom(const Coord3D* pos1,
23782389 b_LowHeightBoundary = b_HiHeightBoundary = pos2->z ;
23792390 break ;
23802391 case BOUNDARY_HEIGHT_CHECK:
2392+ {
23812393 a_LowHeightBoundary = pos1->z - geom1.getMaxHeightAbovePosition ();
23822394 a_HiHeightBoundary = pos1->z + geom1.getMaxHeightAbovePosition ();
2383- b_LowHeightBoundary = pos2->z + geom2.getZDeltaToCenterPosition () - geom2.getBoundingSphereRadius ();
2384- b_HiHeightBoundary = pos2->z + geom2.getZDeltaToCenterPosition () + geom2.getBoundingSphereRadius ();
2395+ if (TheGlobalData->m_useAccurateSphereToRectCollision )
2396+ {
2397+ b_LowHeightBoundary = pos2->z ;
2398+ b_HiHeightBoundary = pos2->z + geom2.getMaxHeightAbovePosition ();
2399+ }
2400+ else
2401+ {
2402+ b_LowHeightBoundary = pos2->z + geom2.getZDeltaToCenterPosition () - geom2.getBoundingSphereRadius ();
2403+ b_HiHeightBoundary = pos2->z + geom2.getZDeltaToCenterPosition () + geom2.getBoundingSphereRadius ();
2404+ }
23852405 break ;
2406+ }
23862407 default :
23872408 a_LowHeightBoundary = pos1->z ;
23882409 a_HiHeightBoundary = pos1->z + geom1.getMaxHeightAbovePosition ();
@@ -2416,11 +2437,12 @@ Bool PartitionManager::geomCollidesWithGeom(const Coord3D* pos1,
24162437 //
24172438 CollideTestProc collideProc = theCollideTestProcs[ (thisGeom - GEOMETRY_FIRST) * GEOMETRY_NUM_TYPES + (thatGeom - GEOMETRY_FIRST) ];
24182439 CollideLocAndNormal cloc;
2419- Bool passCollide = (*collideProc)(&thisInfo, &thatInfo, &cloc);
2440+ cloc.getDistance = heightCheckType == BOUNDARY_HEIGHT_CHECK;
2441+ Bool doesCollide = (*collideProc)(&thisInfo, &thatInfo, &cloc);
24202442
2421- if (abDistSqr)
2443+ if (cloc. getDistance && abDistSqr)
24222444 *abDistSqr = cloc.distSqr ;
2423- return passCollide ;
2445+ return doesCollide ;
24242446 }
24252447 else
24262448 {
0 commit comments