public void InitMap() { if (mainController == null) { mainController = Kernel.Get <MainController>(); } if (capacityController == null) { capacityController = Kernel.Get <CapacityController>(); } minX = mainController.Map.Min(n => n.Coordinates.X); maxX = mainController.Map.Max(n => n.Coordinates.X); minY = mainController.Map.Min(n => n.Coordinates.Y); maxY = mainController.Map.Max(n => n.Coordinates.Y); foreach (var node in mainController.Map.OrderBy(n => !n.IsUnderground)) { float pX = CalculateXPosition(node.Coordinates.X); float pY = CalculateYPosition(node.Coordinates.Y); if (node.Type != NodeType.CarCross) { vertexes.Add( DirectxHelper.CreateCircle( pX, pY, node.Type == NodeType.CarCross ? ViewConsts.GREEN_LIGHT_COLOR.ToArgb() : node.Type == NodeType.TramStop ? ViewConsts.STOP_COLOR.ToArgb() : ViewConsts.POINT_NORMAL_COLOR.ToArgb(), ViewConsts.POINT_RADIUS, ViewConsts.POINT_PRECISION)); } if (node.Child != null) { float pX2 = CalculateXPosition(node.Child.Node.Coordinates.X); float pY2 = CalculateYPosition(node.Child.Node.Coordinates.Y); edges.Add(DirectxHelper.CreateLine(pX, pY, pX2, pY2, GetLineColor(node, node.Child.Node).ToArgb(), ViewConsts.POINT_RADIUS)); } else if (node.Children != null) { foreach (var child in node.Children) { float pX2 = CalculateXPosition(child.Node.Coordinates.X); float pY2 = CalculateYPosition(child.Node.Coordinates.Y); edges.Add(DirectxHelper.CreateLine(pX, pY, pX2, pY2, GetLineColor(node, child.Node).ToArgb(), ViewConsts.POINT_RADIUS)); } } } }
private void DrawVehicles(Device device, Vector3 cameraPosition, Vehicle selectedVehicle) { foreach (var vehicle in mainController.Vehicles) { Color tramColor = capacityController.GetTramColor(vehicle.Passengers); float pX = CalculateXPosition(vehicle.Position.Coordinates.X); float pY = CalculateYPosition(vehicle.Position.Coordinates.Y); float thickness = GetPointRadius(cameraPosition.Z); float selectedThickness = thickness * 1.7f; if (vehicle.Equals(selectedVehicle)) { device.DrawUserPrimitives(PrimitiveType.TriangleFan, ViewConsts.POINT_PRECISION, DirectxHelper.CreateCircle(pX, pY, ViewConsts.SELECTED_COLOR.ToArgb(), selectedThickness, ViewConsts.POINT_PRECISION)); } device.DrawUserPrimitives(PrimitiveType.TriangleFan, ViewConsts.POINT_PRECISION, DirectxHelper.CreateCircle(pX, pY, tramColor.ToArgb(), thickness, ViewConsts.POINT_PRECISION)); float length = VehicleConsts.LENGTH; int actualNodeIndex = vehicle.VisitedNodes.Count - 2; Vector2 prevCoordinates = vehicle.Position.Coordinates; float pX2, pY2; while (length > 0) { if (actualNodeIndex >= 0) { Node actualNode = vehicle.VisitedNodes[actualNodeIndex--]; float distance = prevCoordinates.RealDistanceTo(actualNode); pX = CalculateXPosition(prevCoordinates.X); pY = CalculateYPosition(prevCoordinates.Y); if (distance >= length) { float displacement = (distance - length) * 100 / distance; var pos = GeometryHelper.GetLocactionBetween(displacement, actualNode.Coordinates, prevCoordinates); pX2 = CalculateXPosition(pos.X); pY2 = CalculateYPosition(pos.Y); } else { pX2 = CalculateXPosition(actualNode.Coordinates.X); pY2 = CalculateYPosition(actualNode.Coordinates.Y); prevCoordinates = actualNode.Coordinates; } if (vehicle.Equals(selectedVehicle)) { var selectedTramTail = DirectxHelper.CreateLine(pX, pY, pX2, pY2, ViewConsts.SELECTED_COLOR.ToArgb(), selectedThickness); device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, selectedTramTail); } var tramTail = DirectxHelper.CreateLine(pX, pY, pX2, pY2, tramColor.ToArgb(), thickness); device.DrawUserPrimitives(PrimitiveType.TriangleStrip, 2, tramTail); length -= distance; } else { break; } } } }