Ejemplo n.º 1
0
        public FreeOrWayPoint this[String wpName]
        {
            get {
                wpName = wpName.Trim().ToLower();
                WayPoint  wp = null;
                FreePoint fp = null;
                mWayPointDict.TryGetValue(wpName, out wp);
                if (wp == null)
                {
                    mFreePointDict.TryGetValue(wpName, out fp);
                }

                if (wp != null)
                {
                    return(wp);
                }
                else if (fp != null)
                {
                    return(fp);
                }
                else
                {
                    return(null);
                }
            }
        }
Ejemplo n.º 2
0
        public FreePoint getNearestFreepoint(Vec3f position)
        {
            float     nearestDistance = 0;
            FreePoint foundWP         = null;

            foreach (FreePoint wp in mFreePointList)
            {
                float distance = wp.Position.getDistance(position);
                if (foundWP == null)
                {
                    foundWP         = wp;
                    nearestDistance = distance;
                    continue;
                }
                if (distance < nearestDistance)
                {
                    foundWP         = wp;
                    nearestDistance = distance;
                }
            }

            return(foundWP);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the files file[.wp/.fp]
        /// </summary>
        /// <param name="file"></param>
        /// <returns></returns>
        public static WayNet loadFromFile(String file)
        {
            WayNet wnet = new WayNet();

            if (File.Exists(file + ".wp"))
            {
                String[] lines = File.ReadAllLines(file + ".wp");
                foreach (String line in lines)
                {
                    String[] values = line.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (values.Length < 5)
                    {
                        continue;
                    }

                    String name = values[0].Trim().ToLower();
                    float  x    = float.Parse(values[1].Trim(), System.Globalization.CultureInfo.InvariantCulture);
                    float  y    = float.Parse(values[2].Trim(), System.Globalization.CultureInfo.InvariantCulture);
                    float  z    = float.Parse(values[3].Trim(), System.Globalization.CultureInfo.InvariantCulture);

                    float dirX = float.Parse(values[4].Trim(), System.Globalization.CultureInfo.InvariantCulture);
                    float dirY = float.Parse(values[5].Trim(), System.Globalization.CultureInfo.InvariantCulture);

                    String[] list = new String[values.Length - 6];
                    Array.Copy(values, 6, list, 0, list.Length);

                    WayPoint wp = new WayPoint(name, new Vec3f(x, y, z), new Vec3f(dirX, 0, dirY), list);
                    wnet.mWayPointList.Add(wp);
                    wnet.mWayPointDict.Add(wp.Name, wp);
                }

                foreach (WayPoint wp in wnet.mWayPointList)
                {
                    WayPoint[] wpList = new WayPoint[wp.ConnectedWPString.Length];
                    int        i      = 0;
                    foreach (String wpName in wp.ConnectedWPString)
                    {
                        wpList[i] = wnet.mWayPointDict[wpName];
                        i        += 1;
                    }
                    wp.ConnectedWP = wpList;
                }
            }

            if (File.Exists(file + ".fp"))
            {
                String[] lines = File.ReadAllLines(file + ".fp");
                foreach (String line in lines)
                {
                    String[] values = line.Split(new char[] { ';' }, StringSplitOptions.RemoveEmptyEntries);
                    if (values.Length < 5)
                    {
                        continue;
                    }

                    String name = values[0].Trim().ToLower();

                    float x = float.Parse(values[1].Trim(), System.Globalization.CultureInfo.InvariantCulture);
                    float y = float.Parse(values[2].Trim(), System.Globalization.CultureInfo.InvariantCulture);
                    float z = float.Parse(values[3].Trim(), System.Globalization.CultureInfo.InvariantCulture);

                    float dirX = float.Parse(values[4].Trim(), System.Globalization.CultureInfo.InvariantCulture);
                    float dirZ = float.Parse(values[5].Trim(), System.Globalization.CultureInfo.InvariantCulture);
                    //float dirZ = float.Parse(values[6].Trim(), System.Globalization.CultureInfo.InvariantCulture);


                    FreePoint fp = new FreePoint(name, new Vec3f(x, y, z), new Vec3f(dirX, 0.0f, dirZ));
                    wnet.mFreePointList.Add(fp);
                    wnet.mFreePointDict.Add(fp.Name, fp);
                }
            }

            return(wnet);
        }