Exemplo n.º 1
0
        /// <param name="initialVertex">Initial vertex must represent a bottom left corner</param>
        private Vector2[] GetPolygon(MapVector initialVertex)
        {
            // Algorithm can be understood as moving around the area
            // with a right hand touching the wall allthe time

            // We start with moving right since its a bottom-left corner
            IWallTracingStrategy strategy = new RightWallTracingStrategy(initialVertex, _fields);
            var currentVertex             = initialVertex;
            var i      = 0;
            var output = new List <Vector2>();

            do
            {
                i++;
                output.Add(new Vector2(currentVertex.x, currentVertex.z));
                _wasVisited[currentVertex.z, currentVertex.x] = true;
                strategy = strategy.GoToNextVertex(out currentVertex);
            } while (currentVertex != initialVertex);

            return(output.ToArray());
        }
Exemplo n.º 2
0
        private MapVector[] CheckAndTransformRectangle(Vector2[] rectangle)
        {
            if (rectangle.Length != 4)
            {
                throw new ApplicationException("Registered polygon is not a rectangle.");
            }

            var output = new MapVector[rectangle.Length];

            for (var i = 0; i < rectangle.Length; i++)
            {
                var x = Mathf.RoundToInt(rectangle[i].x);
                var z = Mathf.RoundToInt(rectangle[i].y);
                if (Mathf.Abs(x - rectangle[i].x) + Mathf.Abs(z - rectangle[i].y) > 0.00001)
                {
                    throw new ApplicationException("Sight blockers vertices are not on the grid");
                }

                output[i] = new MapVector(x, z);
            }

            return(output);
        }