Example #1
0
        public void GenerateRoute(Model.Connection.Connection connection, Node to)
        {
            var basePos = NodePosition(CentralNode);
            var toPos   = NodePosition(to);

            int   nearestPlace = 0;
            float nearestDist  = float.MaxValue;

            if (freePlaces.Count == 0)
            {
                DistributeAtElevation(distribution.ChangeBy, (distribution.RingAngleSpan.x + distribution.RingAngleSpan.y) / 2, 5);
            }
            for (var i = 0; i < freePlaces.Count; i++)
            {
                float dist = Vector3.Distance(basePos + freePlaces[i], toPos);
                if (nearestDist > dist)
                {
                    nearestDist  = dist;
                    nearestPlace = i;
                }
            }
            Vector3 chosenPlace = freePlaces[nearestPlace];

            freePlaces.RemoveAt(nearestPlace);
            takenPlaces.Add(chosenPlace);
            connection.ConnectionRoute = ConnectionRouteService.GenerateConnectionRoute(NodePosition(CentralNode), NodePosition(to), chosenPlace);
        }
Example #2
0
 public void OnConnectionUnloaded(Model.Connection.Connection connection)
 {
     takenPlaces.Remove(connection.ConnectionRoute.SpherePoint);
     freePlaces.Add(connection.ConnectionRoute.SpherePoint);
 }