@@ -647,65 +647,58 @@ private void UpdatePointer(PointerData pointer)
647647 /// <param name="prioritizedLayerMasks"></param>
648648 private static void RaycastPhysics ( PointerData pointerData , LayerMask [ ] prioritizedLayerMasks )
649649 {
650- bool isHit = false ;
651- int rayStepIndex = 0 ;
652- RayStep rayStep = default ( RayStep ) ;
653- RaycastHit physicsHit = default ( RaycastHit ) ;
650+ RaycastHit physicsHit ;
651+ RayStep [ ] pointerRays = pointerData . Pointer . Rays ;
654652
655- if ( pointerData . Pointer . Rays == null )
653+ if ( pointerRays == null )
656654 {
657655 Debug . LogError ( $ "No valid rays for { pointerData . Pointer . PointerName } pointer.") ;
658656 return ;
659657 }
660658
661- if ( pointerData . Pointer . Rays . Length <= 0 )
659+ if ( pointerRays . Length <= 0 )
662660 {
663661 Debug . LogError ( $ "No valid rays for { pointerData . Pointer . PointerName } pointer") ;
664662 return ;
665663 }
666664
667665 // Check raycast for each step in the pointing source
668- for ( int i = 0 ; i < pointerData . Pointer . Rays . Length ; i ++ )
666+ for ( int i = 0 ; i < pointerRays . Length ; i ++ )
669667 {
670668 switch ( pointerData . Pointer . RaycastMode )
671669 {
672670 case RaycastMode . Simple :
673- if ( MixedRealityRaycaster . RaycastSimplePhysicsStep ( pointerData . Pointer . Rays [ i ] , prioritizedLayerMasks , out physicsHit ) )
671+ if ( MixedRealityRaycaster . RaycastSimplePhysicsStep ( pointerRays [ i ] , prioritizedLayerMasks , out physicsHit ) )
674672 {
675- // Set the pointer source's origin ray to this step
676- isHit = true ;
677- rayStep = pointerData . Pointer . Rays [ i ] ;
678- rayStepIndex = i ;
673+ UpdatePointerRayOnHit ( pointerData , pointerRays , in physicsHit , i ) ;
674+ return ;
679675 }
680676 break ;
681- case RaycastMode . Box :
682- Debug . LogWarning ( "Box Raycasting Mode not supported for pointers." ) ;
683- break ;
684677 case RaycastMode . Sphere :
685- if ( MixedRealityRaycaster . RaycastSpherePhysicsStep ( pointerData . Pointer . Rays [ i ] , pointerData . Pointer . SphereCastRadius , prioritizedLayerMasks , out physicsHit ) )
678+ if ( MixedRealityRaycaster . RaycastSpherePhysicsStep ( pointerRays [ i ] , pointerData . Pointer . SphereCastRadius , prioritizedLayerMasks , out physicsHit ) )
686679 {
687- // Set the pointer source's origin ray to this step
688- isHit = true ;
689- rayStep = pointerData . Pointer . Rays [ i ] ;
690- rayStepIndex = i ;
680+ UpdatePointerRayOnHit ( pointerData , pointerRays , in physicsHit , i ) ;
681+ return ;
691682 }
692683 break ;
684+ case RaycastMode . Box :
685+ Debug . LogWarning ( "Box Raycasting Mode not supported for pointers." ) ;
686+ break ;
693687 default :
694688 Debug . LogError ( $ "Invalid raycast mode { pointerData . Pointer . RaycastMode } for { pointerData . Pointer . PointerName } pointer.") ;
695689 break ;
696690 }
697-
698- if ( isHit ) { break ; }
699691 }
700692
701- if ( isHit )
702- {
703- pointerData . UpdateHit ( physicsHit , rayStep , rayStepIndex ) ;
704- }
705- else
706- {
707- pointerData . UpdateHit ( ) ;
708- }
693+ pointerData . UpdateHit ( ) ;
694+ }
695+
696+ private static void UpdatePointerRayOnHit ( PointerData pointerData , RayStep [ ] raySteps , in RaycastHit physicsHit , int hitRayIndex )
697+ {
698+ Vector3 origin = raySteps [ hitRayIndex ] . Origin ;
699+ Vector3 terminus = physicsHit . point ;
700+ raySteps [ hitRayIndex ] . UpdateRayStep ( ref origin , ref terminus ) ;
701+ pointerData . UpdateHit ( physicsHit , raySteps [ hitRayIndex ] , hitRayIndex ) ;
709702 }
710703
711704 #endregion Physics Raycasting
0 commit comments