Example #1
0
 void OnEnable()
 {
     _grid    = target as SphereGrid;
     _docsURL = "file://" + Application.dataPath
                + "/Plugins/GridFramework/Documentation/html/"
                + "class_grid_framework_1_1_grids_1_1_sphere_grid.html";
 }
Example #2
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 SphereGrid grid, Vector3 point, CoordinateSystem system)
        {
            var gridVertex = RoundPoint(grid.WorldToGrid(point));

            if (system == CoordinateSystem.Grid)
            {
                return(gridVertex);
            }
            return(system == CoordinateSystem.World ? grid.GridToWorld(gridVertex)
                                                                    : grid.GridToSpheric(gridVertex));
        }
Example #3
0
        /// <summary>
        ///   Returns the grid position of the nearest box.
        /// </summary>
        /// <returns>
        ///   Grid position of the nearest box.
        /// </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 cell in the grid. Since cell lies
        ///     between vertices all three values will always have +0.5
        ///     compared to vertex coordinates.
        ///   </para>
        /// </remarks>
        /// <example>
        ///   <code>
        ///     GFRectGrid myGrid;
        ///     Vector3 worldPoint;
        ///     // something like (2.5, -1.5, 3.5)
        ///     Vector3 box = myGrid.NearestBoxG(worldPoint);
        ///   </code>
        /// </example>
        public static Vector3 NearestCell(this SphereGrid grid,
                                          Vector3 point,
                                          CoordinateSystem system)
        {
            var gridCell = RoundPoint(grid.WorldToGrid(point) - 0.5f * Vector3.one) + 0.5f * Vector3.one;

            if (system == CoordinateSystem.Grid)
            {
                return(gridCell);
            }
            return(system == CoordinateSystem.World ? grid.GridToWorld(gridCell)
                                                                    : grid.GridToSpheric(gridCell));
        }