/// <summary>
        /// Calculates navigation graph based on the largest grid in the surroundings of the character.
        /// </summary>
        /// NOTE: The graph is calculated each time from scratch, it can probably be modified to allow for incremental
        /// updates, but it would be non-trivial. (Extending the platform should be easy, removing blocks or adding
        /// obstacles less easy.
        /// <returns></returns>
        public FatNavGraph GetGraph()
        {
            var sphere = m_lowLevelObserver.GetBoundingSphere(
                m_lowLevelObserver.Radius * 2d);  // Get some look-ahead

            var grid = m_lowLevelObserver.CollectSurroundingBlocks(sphere, ObservationMode.BLOCKS)
                       .OrderByDescending(g => g.Blocks.Count).First(); // Get the biggest grid.

            // TODO: guess which face of the blocks in the grid is "up" (which surface to walk on)
            // perhaps compare the angle of all vectors with the up vector of the character?

            // TODO: offset the start position to be below the character's feet
            // TODO: calculate which direction is actually up
            return(CreateGraph(grid, m_lowLevelObserver.CurrentPlayerPosition(), Vector3I.Up));
        }
Exemple #2
0
        /// <summary>
        /// Calculates navigation graph based on the largest grid in the surroundings of the character.
        /// </summary>
        /// NOTE: The graph is calculated each time from scratch, it can probably be modified to allow for incremental
        /// updates, but it would be non-trivial. (Extending the platform should be easy, removing blocks or adding
        /// obstacles less easy.
        /// <returns></returns>
        public FatNavGraph GetGraph()
        {
            var sphere = m_lowLevelObserver.GetBoundingSphere(
                null,
                m_lowLevelObserver.Radius * 2d);  // Get some look-ahead

            var sourceGrid = m_lowLevelObserver.Grids().ToList()
                             .OrderByDescending(g => g.BlocksCount).First(); // Get the biggest grid.

            // Convert both "ends" of the orientation vector
            var zeroInGridCoordinates        = sourceGrid.WorldToGridScaledLocal(Vector3D.Zero);
            var characterOrientationUpInGrid = sourceGrid.WorldToGridScaledLocal(
                m_lowLevelObserver.CurrentPlayerOrientationUp()) - zeroInGridCoordinates;

            // TODO: offset the start position to be below the character's feet
            return(CreateGraph(m_lowLevelObserver.ConvertToSeGrid(sourceGrid, sphere),
                               m_lowLevelObserver.CurrentPlayerPosition(),
                               GuessWhichSideIsUp(characterOrientationUpInGrid)));
        }