Exemplo n.º 1
0
        public static float GetNextStopDistance(this TramLine line, Node node)
        {
            Node.Next next     = line.GetNextNode(node);
            float     distance = next.Distance;

            while (!(next.Node.Type == NodeType.TramStop && line.MainNodes.Any(n => n.Equals(next.Node))))
            {
                next      = line.GetNextNode(next.Node);
                distance += next.Distance;
            }

            return(distance);
        }
Exemplo n.º 2
0
        private void CalculatePosition(Vehicle vehicle, float prevSpeed, float deltaTime)
        {
            float translation = PhysicsHelper.GetTranslation(prevSpeed, vehicle.Speed, deltaTime);

            if (vehicle.Position.Node2 != null)
            {
                float distanceToNextPoint = vehicle.RealDistanceTo(vehicle.Position.Node2);
                if (distanceToNextPoint > translation)
                {
                    vehicle.Position.Displacement += translation * 100 / vehicle.Position.Node1.GetDistanceToChild(vehicle.Position.Node2);
                }
                else
                {
                    Node.Next newNode = vehicle.Line.GetNextNode(vehicle.Position.Node2);
                    if (newNode != null)
                    {
                        vehicle.VisitedNodes.Add(newNode.Node);
                        vehicle.Position.Node1.VehiclesOn.Remove(vehicle);
                        vehicle.Position.Node1 = vehicle.Position.Node2;
                        vehicle.Position.Node1.VehiclesOn.Add(vehicle);
                        vehicle.Position.Node2         = newNode.Node;
                        vehicle.Position.Displacement  = 0;
                        vehicle.Position.Displacement += (translation - distanceToNextPoint) * 100 / vehicle.Position.Node1.GetDistanceToChild(vehicle.Position.Node2);
                    }
                }
            }

            if (translation > 0)
            {
                vehicle.Position.Coordinates = vehicle.Position.Node2 == null || vehicle.Position.Displacement < CalculationConsts.EPSILON ?
                                               vehicle.Position.Node1.Coordinates :
                                               GeometryHelper.GetLocactionBetween(vehicle.Position.Displacement, vehicle.Position.Node1.Coordinates, vehicle.Position.Node2.Coordinates);
            }

            //Check intersection
            if (vehicle.CurrentIntersection != null && (!vehicle.IsStillOnIntersection() || FinishCoursePredicate(vehicle)))
            {
                DequeueIntersection(vehicle.CurrentIntersection);
                vehicle.LastIntersection    = vehicle.CurrentIntersection;
                vehicle.CurrentIntersection = null;
            }
        }