public MovingBlocksRaycastResult?Raycast(Vector3 start, Vector3 end, bool extendToFillCells) { Ray3 ray = new Ray3(start, Vector3.Normalize(end - start)); BoundingBox boundingBox = new BoundingBox(Vector3.Min(start, end), Vector3.Max(start, end)); m_result.Clear(); FindMovingBlocks(boundingBox, extendToFillCells, m_result); float num = float.MaxValue; MovingBlockSet movingBlockSet = null; foreach (MovingBlockSet item in m_result) { BoundingBox box = item.BoundingBox(extendToFillCells); float? num2 = ray.Intersection(box); if (num2.HasValue && num2.Value < num) { num = num2.Value; movingBlockSet = item; } } if (movingBlockSet != null) { MovingBlocksRaycastResult value = default(MovingBlocksRaycastResult); value.Ray = ray; value.Distance = num; value.MovingBlockSet = movingBlockSet; return(value); } return(null); }
public void DrawRayHighlight(Camera camera) { if (!camera.Eye.HasValue) { return; } Ray3 ray = default(Ray3); float num; if (m_highlightRaycastResult is TerrainRaycastResult) { TerrainRaycastResult obj = (TerrainRaycastResult)m_highlightRaycastResult; ray = obj.Ray; num = MathUtils.Min(obj.Distance, 2f); } else if (m_highlightRaycastResult is BodyRaycastResult) { BodyRaycastResult obj2 = (BodyRaycastResult)m_highlightRaycastResult; ray = obj2.Ray; num = MathUtils.Min(obj2.Distance, 2f); } else if (m_highlightRaycastResult is MovingBlocksRaycastResult) { MovingBlocksRaycastResult obj3 = (MovingBlocksRaycastResult)m_highlightRaycastResult; ray = obj3.Ray; num = MathUtils.Min(obj3.Distance, 2f); } else { if (!(m_highlightRaycastResult is Ray3)) { return; } ray = (Ray3)m_highlightRaycastResult; num = 2f; } Color color = Color.White * 0.5f; Color color2 = Color.Lerp(color, Color.Transparent, MathUtils.Saturate(num / 2f)); FlatBatch3D flatBatch3D = m_primitivesRenderer3D.FlatBatch(); flatBatch3D.QueueLine(ray.Position, ray.Position + ray.Direction * num, color, color2); flatBatch3D.Flush(camera.ViewProjectionMatrix); }