2121namespace VJoltTrace
2222{
2323
24- static constexpr float kCollisionTolerance = 1 .0e-3f ;
25- static constexpr float kCharacterPadding = 0 .02f ;
26-
27- // Also in vjolt_collide.cpp, should unify or just remove entirely
28- static constexpr float kMaxConvexRadius = SourceToJolt::Distance( DIST_EPSILON * 2 .0f );
29-
3024static ConVar vjolt_trace_debug ( " vjolt_trace_debug" , " 0" , FCVAR_CHEAT );
3125static ConVar vjolt_trace_debug_castray ( " vjolt_trace_debug_castray" , " 0" , FCVAR_CHEAT );
3226static ConVar vjolt_trace_debug_collidepoint ( " vjolt_trace_debug_collidepoint" , " 0" , FCVAR_CHEAT );
@@ -527,7 +521,6 @@ static void CastBoxVsShape( const Ray_t &ray, uint32 contentsMask, IConvexInfo *
527521
528522 JPH::BoxShape boxShape ( halfExtent, kMaxConvexRadius );
529523 JPH::ShapeCast shapeCast ( &boxShape, JPH::Vec3::sReplicate ( 1 .0f ), JPH::Mat44::sTranslation ( origin ), direction );
530- // JPH::ShapeCast shapeCast = JPH::ShapeCast::sFromWorldTransform( &boxShape, JPH::Vec3::sReplicate( 1.0f ), JPH::Mat44::sTranslation( origin ), direction );
531524
532525 JPH::ShapeCastSettings settings;
533526 // settings.mBackFaceModeTriangles = JPH::EBackFaceMode::CollideWithBackFaces;
@@ -537,43 +530,26 @@ static void CastBoxVsShape( const Ray_t &ray, uint32 contentsMask, IConvexInfo *
537530 settings.mBackFaceModeConvex = JPH::EBackFaceMode::CollideWithBackFaces;
538531 if ( vjolt_trace_castbox_backface_force.GetBool () )
539532 settings.SetBackFaceMode ( JPH::EBackFaceMode::CollideWithBackFaces );
540- // settings.mCollisionTolerance = kCollisionTolerance;
533+ settings.mCollisionTolerance = SourceToJolt::Distance ( 0 . 1f * 0 . 25f ); // Regular VPhysics uses 0.25" here for the "collision tolerance"/epsilon, but when actually testing, it uses 0.1 * epsilon, so provide that here.
541534 settings.mUseShrunkenShapeAndConvexRadius = true ;
542535 settings.mReturnDeepestPoint = false ;
543- // settings.mReturnDeepestPoint = true;
544-
545- // settings.mActiveEdgeMode = JPH::EActiveEdgeMode::CollideWithAll;
546- // settings.mCollectFacesMode = JPH::ECollectFacesMode::CollectFaces;
547- // settings.mActiveEdgeMode = JPH::EActiveEdgeMode::CollideOnlyWithActive;
548- // settings.mBackFaceModeConvex = JPH::EBackFaceMode::IgnoreBackFaces;
549536
550537 ContentsFilter_Shape filter ( pShape, contentsMask, pConvexInfo );
551538 ContentsCollector_CastShape collector ( pShape, contentsMask, pConvexInfo, direction );
552539 JPH::CollisionDispatch::sCastShapeVsShapeWorldSpace ( shapeCast, settings, pShape, JPH::Vec3::sReplicate ( 1 .0f ), filter, queryTransform, JPH::SubShapeIDCreator (), JPH::SubShapeIDCreator (), collector );
553540
554541 if ( collector.m_DidHit )
555542 {
556- // JPH::Vec3 normal = collector.m_ContactNormal;
557- // JPH::Vec3 normal = queryTransform.GetRotation() * pShape->GetSurfaceNormal( collector.m_SubShapeID, joltRay.GetPointOnRay( collector.m_Fraction ) );
558- // JPH::Vec3 normal = queryTransform.GetRotation() * pShape->GetSurfaceNormal( collector.m_SubShapeID, collector.m_ContactPoint );
559543 JPH::Vec3 normal = -( collector.m_PenetrationAxis .Normalized () );
560544 pTrace->plane .normal = Vector ( normal.GetX (), normal.GetY (), normal.GetZ () );
561- pTrace->fraction = CalculateSourceFraction (ray.m_Delta , collector.m_Fraction , pTrace->plane .normal );
562-
563- // Log_Msg( LOG_VJolt, "BoxCast Normal %g %g %g\n", normal.GetX(), normal.GetY(), normal.GetZ() );
545+ pTrace->fraction = CalculateSourceFraction ( ray.m_Delta , collector.m_Fraction , pTrace->plane .normal );
564546
565547 pTrace->startpos = ray.m_Start + ray.m_StartOffset ;
566548 pTrace->endpos = pTrace->startpos + ( ray.m_Delta * pTrace->fraction );
567549
568- // pTrace->endpos -= pTrace->plane.normal * collector.m_PenetrationDepth;
569-
570550 pTrace->plane .dist = DotProduct ( pTrace->endpos , pTrace->plane .normal );
571551 pTrace->contents = collector.m_ResultContents ;
572552
573- // If penetrating more than DIST_EPSILON, consider it an intersection
574- // constexpr float PenetrationEpsilon = DIST_EPSILON;
575- static constexpr float kMinRequiredPenetration = SourceToJolt::Distance ( DIST_EPSILON );
576-
577553 pTrace->allsolid = collector.m_bStartSolid && collector.m_bEndSolid ;
578554 pTrace->startsolid = collector.m_bStartSolid ;
579555 }
@@ -589,7 +565,6 @@ static void CastBoxVsShape( const Ray_t &ray, uint32 contentsMask, IConvexInfo *
589565 }
590566
591567#if defined JPH_DEBUG_RENDERER
592-
593568 // Debug trace visualizing
594569 IVJoltDebugOverlay *pOverlay = JoltPhysicsInterface::GetInstance ().GetDebugOverlay ();
595570 if ( vjolt_trace_debug.GetBool () && vjolt_trace_debug_castbox.GetBool () && pOverlay )
0 commit comments