public void StartMapping(string mapName)
        {
            // Opens a text file and starts streaming "{x} {y} {z} {angle} {collisionName}" entries into it,
            // depending on distance from existing values.

            string           timestamp    = DateTime.Now.ToString("yyyyMMdd_hhmm");
            List <GamePoint> allPositions = new List <GamePoint>();

            using (System.IO.StreamWriter file = new System.IO.StreamWriter($"{mapName}_{timestamp}.txt"))
            {
                Console.WriteLine("Press ESC to stop");
                do
                {
                    while (!Console.KeyAvailable)
                    {
                        GamePoint point = GetPositionInfo();
                        if (point != null && CheckDistance(point, allPositions))
                        {
                            if (!point.CollisionName.StartsWith("unknown"))
                            {
                                allPositions.Add(point);
                                Console.WriteLine(point);
                                file.WriteLine(point.ToString());
                            }
                            else
                            {
                                Console.WriteLine("UNKNOWN (not written) " + point.ToString());
                            }
                        }
                        Thread.Sleep(MappingInterval);
                    }
                } while (Console.ReadKey(true).Key != ConsoleKey.Escape);
            }
        }
        public float SquaredDistanceFromPoint(GamePoint otherPoint)
        {
            Vector3 delta = Position - otherPoint.Position;

            delta *= delta;
            return(delta.X + delta.Y + delta.Z);
        }
 bool CheckDistance(GamePoint newPoint, List <GamePoint> allPoints)
 {
     // Returns true if newPosition is sufficiently far away from other positions in the map.
     if (allPoints.Count == 0)
     {
         return(true);
     }
     foreach (GamePoint point in allPoints)
     {
         Vector3 delta = point.Position - newPoint.Position;
         float   horizontalDistanceSq = delta.X * delta.X + delta.Z * delta.Z;
         float   verticalDistanceSq   = delta.Y * delta.Y;
         if (horizontalDistanceSq < MinPointDistanceHorizontalSquared && verticalDistanceSq < MinPointDistanceVerticalSquared)
         {
             return(false);  // too close to an existing point
         }
     }
     return(true);
 }
Exemplo n.º 4
0
 public float SquaredDistanceFromPoint(GamePoint otherPoint)
 {
     return(SquaredDistanceFromPoint(otherPoint.Position));
 }