コード例 #1
0
        public Status AddBoxObstacle(Vector3 center, Vector3 halfExtents, float yRadians, out int result)
        {
            result = 0;

            if (m_nreqs >= DetourTileCache.MAX_REQUESTS)
            {
                return(Status.DT_FAILURE | Status.DT_BUFFER_TOO_SMALL);
            }

            int ob = -1;

            if (m_nextFreeObstacle >= 0)
            {
                ob = m_nextFreeObstacle;
                m_nextFreeObstacle   = m_obstacles[ob].Next;
                m_obstacles[ob].Next = -1;
            }
            if (ob == -1)
            {
                return(Status.DT_FAILURE);
            }

            float coshalf = (float)Math.Cos(0.5f * yRadians);
            float sinhalf = (float)Math.Sin(-0.5f * yRadians);
            var   rotAux  = new Vector2(coshalf * sinhalf, coshalf * coshalf - 0.5f);

            int salt = m_obstacles[ob].Salt;

            m_obstacles[ob] = new TileCacheObstacle
            {
                Salt        = salt,
                State       = ObstacleState.DT_OBSTACLE_PROCESSING,
                Type        = ObstacleType.DT_OBSTACLE_ORIENTED_BOX,
                OrientedBox = new ObstacleOrientedBox
                {
                    Center      = center,
                    HalfExtents = halfExtents,
                    RotAux      = rotAux,
                }
            };

            var req = new ObstacleRequest
            {
                Action = ObstacleRequestAction.REQUEST_ADD,
                NRef   = GetObstacleRef(m_obstacles[ob])
            };

            m_reqs[m_nreqs++] = req;

            result = req.NRef;

            return(Status.DT_SUCCESS);
        }
コード例 #2
0
        public Status AddObstacle(Vector3 pos, float radius, float height, out int result)
        {
            result = 0;

            if (m_nreqs >= DetourTileCache.MAX_REQUESTS)
            {
                return(Status.DT_FAILURE | Status.DT_BUFFER_TOO_SMALL);
            }

            int ob = -1;

            if (m_nextFreeObstacle >= 0)
            {
                ob = m_nextFreeObstacle;
                m_nextFreeObstacle   = m_obstacles[ob].Next;
                m_obstacles[ob].Next = -1;
            }
            if (ob == -1)
            {
                return(Status.DT_FAILURE);
            }

            int salt = m_obstacles[ob].Salt;

            m_obstacles[ob] = new TileCacheObstacle
            {
                Salt     = salt,
                State    = ObstacleState.DT_OBSTACLE_PROCESSING,
                Type     = ObstacleType.DT_OBSTACLE_CYLINDER,
                Cylinder = new ObstacleCylinder
                {
                    Pos    = pos,
                    Radius = radius,
                    Height = height
                }
            };

            var req = new ObstacleRequest
            {
                Action = ObstacleRequestAction.REQUEST_ADD,
                NRef   = GetObstacleRef(m_obstacles[ob]),
            };

            m_reqs[m_nreqs++] = req;

            result = req.NRef;

            return(Status.DT_SUCCESS);
        }
コード例 #3
0
        public Status AddBoxObstacle(Vector3 bmin, Vector3 bmax, out int result)
        {
            result = 0;

            if (m_nreqs >= DetourTileCache.MAX_REQUESTS)
            {
                return(Status.DT_FAILURE | Status.DT_BUFFER_TOO_SMALL);
            }

            int ob = -1;

            if (m_nextFreeObstacle >= 0)
            {
                ob = m_nextFreeObstacle;
                m_nextFreeObstacle   = m_obstacles[ob].Next;
                m_obstacles[ob].Next = -1;
            }
            if (ob == -1)
            {
                return(Status.DT_FAILURE);
            }

            int salt = m_obstacles[ob].Salt;

            m_obstacles[ob] = new TileCacheObstacle
            {
                Salt  = salt,
                State = ObstacleState.DT_OBSTACLE_PROCESSING,
                Type  = ObstacleType.DT_OBSTACLE_BOX,
                Box   = new ObstacleBox
                {
                    BMin = bmin,
                    BMax = bmax
                }
            };

            var req = new ObstacleRequest
            {
                Action = ObstacleRequestAction.REQUEST_ADD,
                NRef   = GetObstacleRef(m_obstacles[ob])
            };

            m_reqs[m_nreqs++] = req;

            result = req.NRef;

            return(Status.DT_SUCCESS);
        }
コード例 #4
0
        public Status RemoveObstacle(int r)
        {
            if (r == 0)
            {
                return(Status.DT_SUCCESS);
            }
            if (m_nreqs >= DetourTileCache.MAX_REQUESTS)
            {
                return(Status.DT_FAILURE | Status.DT_BUFFER_TOO_SMALL);
            }

            var req = new ObstacleRequest
            {
                Action = ObstacleRequestAction.REQUEST_REMOVE,
                NRef   = r
            };

            m_reqs[m_nreqs++] = req;

            return(Status.DT_SUCCESS);
        }