Ejemplo n.º 1
0
        /// <summary>
        ///   Returns the position of the nearest vertex.
        /// </summary>
        /// <returns>
        ///   Position of the nearest vertex.
        /// </returns>
        ///
        /// <param name="grid">
        ///   The rectangular grid instance.
        /// </param>
        /// <param name="point">
        ///   Point in world space.
        /// </param>
        /// <param name="system">
        ///   Coordinate system to use.
        /// </param>
        ///
        /// <remarks>
        ///   Returns the position of the nearest vertex from a given point in
        ///   either grid- or world space.
        /// </remarks>
        public static Vector3 NearestVertex(this PolarGrid grid, Vector3 point, CoordinateSystem system)
        {
            var gridPoint = grid.WorldToGrid(point);

            for (var i = 0; i < 3; ++i)
            {
                gridPoint[i] = Mathf.Round(gridPoint[i]);
            }

            return(GridToCoordinateSystem(grid, gridPoint, system));
        }
Ejemplo n.º 2
0
        /// <summary>
        ///   Returns the position of the nearest face.
        /// </summary>
        /// <returns>
        ///   Position of the nearest face.
        /// </returns>
        /// <param name="grid">
        ///   The rectangular grid instance.
        /// </param>
        /// <param name="point">
        ///   Point in world space.
        /// </param>
        /// <param name="system">
        ///   Coordinate system to use.
        /// </param>
        ///
        /// <remarks>
        ///   <para>
        ///     Returns the coordinates of a face on the grid closest to a
        ///     given point. Since the face is enclosed by four vertices, the
        ///     returned value is the point in between all four of the
        ///     vertices. You also need to specify on which plane the face
        ///     lies.
        ///   </para>
        /// </remarks>
        public static Vector3 NearestFace(this PolarGrid grid,
                                          Vector3 point,
                                          CoordinateSystem system)
        {
            Vector3 gridPoint = grid.WorldToGrid(point);

            gridPoint.x = Mathf.Floor(gridPoint.x) + .5f;
            gridPoint.y = Mathf.Floor(gridPoint.y) + .5f;
            gridPoint.z = Mathf.Round(gridPoint.z);

            return(GridToCoordinateSystem(grid, gridPoint, system));
        }
Ejemplo n.º 3
0
        /// <summary>
        ///   Converts a world position to the sector of the grid it is in.
        /// </summary>
        /// <returns>
        ///   Sector the point is in.
        /// </returns>
        /// <param name="grid">
        ///   The polar grid instance.
        /// </param>
        /// <param name="world">
        ///   Point in world space.
        /// </param>
        /// <remarks>
        ///   <para>
        ///     This method returns which which sector a given point in world
        ///     space is in.
        ///   </para>
        /// </remarks>
        public static float World2Sector(this PolarGrid grid, Vector3 world)
        {
            var gridPoint = grid.WorldToGrid(world);

            return(gridPoint.y);
        }