/// <summary> /// Casts a virtual ray using _raycastParams for origin and direction /// </summary> protected void CastVirtualRay(float distance) { #if PLATFORM_LUMIN if (Physics.Raycast(_raycastParams.Position, _raycastParams.Direction, out _raycastResult, distance, virtualRayProperties.hitLayerMask)) { _ray.origin = _raycastParams.Position; _ray.direction = _raycastParams.Direction; OnRaycastResult?.Invoke(MLRaycast.ResultState.HitObserved, Mode.Virtual, _ray, _raycastResult, 1.0f); } #endif }
/// <summary> /// Callback handler called when raycast call has a result /// </summary> /// <param name="hit"> Stores if there is a hit. </param> /// <param name="point"> Position of the hit. </param> /// <param name="normal"> Normal of the surface hit. </param> /// <param name="confidence"> Confidence value on hit. </param> protected override void HandleOnReceiveRaycast(bool hit, Vector3 point, Vector3 normal, float confidence) { RaycastHit result = GetWorldRaycastResult(hit, point, normal, confidence); // If there was a hit on world raycast, change max distance to the hitpoint distance float maxDist = (result.distance > 0.0f) ? result.distance : Mathf.Infinity; // Virtual Raycast Ray ray = new Ray(_raycastParams.Position, _raycastParams.Direction); if (Physics.Raycast(ray, out result, maxDist, _hitLayerMask)) { confidence = 1.0f; } OnRaycastResult.Invoke(result, confidence); _isReady = true; }
/// <summary> /// Callback handler called when raycast call has a result. /// </summary> /// <param name="state"> The state of the raycast result.</param> /// <param name="point"> Position of the hit.</param> /// <param name="normal"> Normal of the surface hit.</param> /// <param name="confidence"> Confidence value on hit.</param> protected void HandleOnReceiveRaycast(MLRaycast.ResultState state, Vector3 point, Vector3 normal, float confidence) { if (state == MLRaycast.ResultState.HitObserved || state == MLRaycast.ResultState.HitUnobserved) { if (_modeOnWorldRaycast == Mode.World) { SetWorldRaycastResult(state, point, normal); OnRaycastResult?.Invoke(state, Mode.World, _ray, _raycastResult, confidence); } if (_modeOnWorldRaycast == Mode.Combination) { // If there was a hit on world raycast, change max distance to the hitpoint distance float maxDist = (_raycastResult.distance > 0.0f) ? (_raycastResult.distance + WorldRayProperties.bias) : virtualRayProperties.distance; CastVirtualRay(maxDist); } } _isReady = true; }