private void BoxRaycastStepUpdate(RayStep rayStep) { Vector3 scale = transform.lossyScale; float scaleOverride = ScaleOverride; if (scaleOverride > 0) { scale = scale.normalized * scaleOverride; } Quaternion orientation = orientationMode == OrientModeEnum.None ? Quaternion.LookRotation(rayStep.Direction, Vector3.up) : CalculateMagnetismOrientation(rayStep.Direction, Vector3.up); Matrix4x4 targetMatrix = Matrix4x4.TRS(Vector3.zero, orientation, scale); if (boxCollider == null) { boxCollider = GetComponent <BoxCollider>(); } Debug.Assert(boxCollider != null, $"Missing a box collider for Surface Magnetism on {gameObject}"); Vector3 extents = boxCollider.size; if (MixedRealityRaycaster.RaycastBoxPhysicsStep(rayStep, extents, transform.position, targetMatrix, maxDistance, magneticSurfaces, boxRaysPerEdge, orthographicBoxCast, out Vector3[] positions, out Vector3[] normals, out bool[] hits))
private void BoxRaycastStepUpdate(RayStep rayStep) { Vector3 scale = transform.lossyScale; float scaleOverride = ScaleOverride; if (scaleOverride > 0) { scale = scale.normalized * scaleOverride; } Quaternion orientation = orientationMode == OrientModeEnum.None ? Quaternion.LookRotation(rayStep.Direction, Vector3.up) : CalculateMagnetismOrientation(rayStep.Direction, Vector3.up); Matrix4x4 targetMatrix = Matrix4x4.TRS(Vector3.zero, orientation, scale); if (boxCollider == null) { boxCollider = GetComponent <BoxCollider>(); } Debug.Assert(boxCollider != null, $"Missing a box collider for Surface Magnetism on {gameObject}"); Vector3 extents = boxCollider.size; Vector3[] positions; Vector3[] normals; bool[] hits; if (MixedRealityRaycaster.RaycastBoxPhysicsStep(rayStep, extents, transform.position, targetMatrix, maxDistance, magneticSurfaces, boxRaysPerEdge, orthographicBoxCast, out positions, out normals, out hits)) { Plane plane; float distance; // Place an unconstrained plane down the ray. Don't use vertical constrain. FindPlacementPlane(rayStep.Origin, rayStep.Direction, positions, normals, hits, boxCollider.size.x, maximumNormalVariance, false, orientationMode == OrientModeEnum.None, out plane, out distance); // If placing on a horizontal surface, need to adjust the calculated distance by half the app height float verticalCorrectionOffset = 0; if (IsNormalVertical(plane.normal) && !Mathf.Approximately(rayStep.Direction.y, 0)) { float boxSurfaceVerticalOffset = targetMatrix.MultiplyVector(new Vector3(0, extents.y * 0.5f, 0)).magnitude; Vector3 correctionVector = boxSurfaceVerticalOffset * (rayStep.Direction / rayStep.Direction.y); verticalCorrectionOffset = -correctionVector.magnitude; } float boxSurfaceOffset = targetMatrix.MultiplyVector(new Vector3(0, 0, extents.z * 0.5f)).magnitude; // Apply boxSurfaceOffset to ray direction and not surface normal direction to reduce sliding GoalPosition = rayStep.Origin + rayStep.Direction * Mathf.Max(closeDistance, distance + surfaceRayOffset + boxSurfaceOffset + verticalCorrectionOffset) + plane.normal * (0 * boxSurfaceOffset + surfaceNormalOffset); GoalRotation = CalculateMagnetismOrientation(rayStep.Direction, plane.normal); OnSurface = true; } else { OnSurface = false; } }