Beispiel #1
0
        private void NewMoveOrder(IContext context, Fleet fleet)
        {
            if (_items.ContainsKey(fleet))
            {
                _items[fleet].Dispose();
            }
            if (fleet.MoveOrder == null)
            {
                _items.Remove(fleet);
                return;
            }
            List <Step> steps = fleet.MoveOrder.Steps.ToList();
            List <VertexDefinition.Path> vertices = new List <VertexDefinition.Path>();
            int     index         = 0;
            Vector3 prevPosition  = (Vector3)steps[0].Source.Center;
            float   totalDistance = 0.0f;

            for (int i = 0; i < steps.Count; i++)
            {
                Vector3 middlePoint = (Vector3)steps[i].Destination.Adjacencies.Single(a => a.Neighbourg == steps[i].Source).PassingPoints.First();
                Vector3 startPoint  = (Vector3)steps[i].Source.Center;
                Vector3 endPoint    = (Vector3)steps[i].Destination.Center;
                Vector3 prevPoint   = i == 0 ? startPoint :
                                      (Vector3)steps[i].Source.Adjacencies.Single(a => a.Neighbourg == steps[i - 1].Source).PassingPoints.First();
                Vector3 nextPoint = i == steps.Count - 1 ? endPoint :
                                    (Vector3)steps[i].Destination.Adjacencies.Single(a => a.Neighbourg == steps[i + 1].Destination).PassingPoints.First();
                //First part of the arc
                for (int j = 0; j < ArcSubdivisions; j++)
                {
                    Vector3 position  = Vector3.CatmullRom(prevPoint, startPoint, middlePoint, endPoint, (1.0f * j) / ArcSubdivisions);
                    float   arcLength = Vector3.Distance(prevPosition, position);
                    vertices.Add(new VertexDefinition.Path
                    {
                        fillingIndex = (uint)(++index),
                        position     = position,
                        pathLength   = new Vector2(totalDistance, arcLength)
                    });
                    totalDistance += arcLength;
                    prevPosition   = position;
                }
                //Second part of the arc
                for (int j = 0; j < ArcSubdivisions; j++)
                {
                    Vector3 position  = Vector3.CatmullRom(startPoint, middlePoint, endPoint, nextPoint, (1.0f * j) / ArcSubdivisions);
                    float   arcLength = Vector3.Distance(prevPosition, position);
                    vertices.Add(new VertexDefinition.Path
                    {
                        fillingIndex = (uint)(++index),
                        position     = position,
                        pathLength   = new Vector2(totalDistance, arcLength)
                    });
                    totalDistance += arcLength;
                    prevPosition   = position;
                }
            }
            _items[fleet] = new MoveOrderRenderingItem(
                vertices.Count,
                Buffer.Create(context.DirectX.Device, BindFlags.VertexBuffer, vertices.ToArray()),
                fleet.Speed);
        }
Beispiel #2
0
 private void NewMoveOrder(IContext context, Fleet fleet)
 {
     if (_items.ContainsKey(fleet))
     {
         _items[fleet].Dispose();
     }
     if (fleet.MoveOrder == null)
     {
         _items.Remove(fleet);
         return;
     }
     List<Step> steps = fleet.MoveOrder.Steps.ToList();
     List<VertexDefinition.Path> vertices = new List<VertexDefinition.Path>();
     int index = 0;
     Vector3 prevPosition = (Vector3) steps[0].Source.Center;
     float totalDistance = 0.0f;
     for(int i = 0; i<steps.Count ; i++)
     {
         Vector3 middlePoint = (Vector3)steps[i].Destination.Adjacencies.Single(a => a.Neighbourg == steps[i].Source).PassingPoints.First();
         Vector3 startPoint = (Vector3)steps[i].Source.Center;
         Vector3 endPoint = (Vector3)steps[i].Destination.Center;
         Vector3 prevPoint = i == 0 ? startPoint :
             (Vector3)steps[i].Source.Adjacencies.Single(a => a.Neighbourg == steps[i - 1].Source).PassingPoints.First();
         Vector3 nextPoint = i == steps.Count -1 ? endPoint :
             (Vector3)steps[i].Destination.Adjacencies.Single(a => a.Neighbourg == steps[i + 1].Destination).PassingPoints.First();
         //First part of the arc
         for (int j = 0; j < ArcSubdivisions; j++)
         {
             Vector3 position = Vector3.CatmullRom(prevPoint, startPoint, middlePoint, endPoint, (1.0f * j) / ArcSubdivisions);
             float arcLength = Vector3.Distance(prevPosition, position);
             vertices.Add(new VertexDefinition.Path
             {
                 fillingIndex = (uint)(++index),
                 position = position,
                 pathLength = new Vector2(totalDistance, arcLength)
             });
             totalDistance += arcLength;
             prevPosition = position;
         }
         //Second part of the arc
         for (int j = 0; j < ArcSubdivisions; j++)
         {
             Vector3 position = Vector3.CatmullRom(startPoint, middlePoint, endPoint, nextPoint, (1.0f * j) / ArcSubdivisions);
             float arcLength = Vector3.Distance(prevPosition, position);
             vertices.Add(new VertexDefinition.Path
             {
                 fillingIndex = (uint)(++index),
                 position = position,
                 pathLength = new Vector2(totalDistance, arcLength)
             });
             totalDistance += arcLength;
             prevPosition = position;
         }
     }
     _items[fleet] = new MoveOrderRenderingItem(
         vertices.Count,
         Buffer.Create(context.DirectX.Device, BindFlags.VertexBuffer, vertices.ToArray()),
         fleet.Speed);
 }