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); }
public BodyRaycastResult?Raycast(Vector3 start, Vector3 end, float inflateAmount, Func <ComponentBody, float, bool> action) { float num = Vector3.Distance(start, end); Ray3 ray = new Ray3(start, (num > 0f) ? ((end - start) / num) : Vector3.UnitX); Vector2 corner = new Vector2(start.X, start.Z); Vector2 corner2 = new Vector2(end.X, end.Z); BodyRaycastResult bodyRaycastResult = default(BodyRaycastResult); bodyRaycastResult.Ray = ray; bodyRaycastResult.Distance = float.MaxValue; BodyRaycastResult value = bodyRaycastResult; m_componentBodies.Clear(); FindBodiesInArea(corner, corner2, m_componentBodies); for (int i = 0; i < m_componentBodies.Count; i++) { ComponentBody componentBody = m_componentBodies.Array[i]; float? num2; if (inflateAmount > 0f) { BoundingBox boundingBox = componentBody.BoundingBox; boundingBox.Min -= new Vector3(inflateAmount); boundingBox.Max += new Vector3(inflateAmount); num2 = ray.Intersection(boundingBox); } else { num2 = ray.Intersection(componentBody.BoundingBox); } if (num2.HasValue && num2.Value <= num && num2.Value < value.Distance && action(componentBody, num2.Value)) { value.Distance = num2.Value; value.ComponentBody = componentBody; } } if (value.ComponentBody == null) { return(null); } return(value); }