private int AddTriangle(int index)
            {
                if (!m_funnelConstructed)
                {
                    ConstructFunnel(index);
                }
                else
                {
                    MyPath <MyNavigationPrimitive> .PathNode tri = m_input[index];

                    Vector3 left, right;
                    var     triangle = tri.Vertex as MyNavigationTriangle;
                    Debug.Assert(triangle != null, "Path did not consist of triangles only!");

                    var edge = triangle.GetNavigationEdge(tri.nextVertex);
                    GetEdgeVerticesSafe(triangle, tri.nextVertex, out left, out right);

                    PointTestResult leftResult  = TestPoint(left);
                    PointTestResult rightResult = TestPoint(right);

                    if (leftResult == PointTestResult.INSIDE)
                    {
                        NarrowFunnel(left, index, left: true);
                    }
                    if (rightResult == PointTestResult.INSIDE)
                    {
                        NarrowFunnel(right, index, left: false);
                    }

                    if (leftResult == PointTestResult.RIGHT)
                    {
                        m_apex = m_rightPoint;
                        m_funnelConstructed = false;
                        ConstructFunnel(m_rightIndex + 1);
                        return(m_rightIndex + 1);
                    }
                    if (rightResult == PointTestResult.LEFT)
                    {
                        m_apex = m_leftPoint;
                        m_funnelConstructed = false;
                        ConstructFunnel(m_leftIndex + 1);
                        return(m_leftIndex + 1);
                    }
                    if (leftResult == PointTestResult.INSIDE || rightResult == PointTestResult.INSIDE)
                    {
                        m_debugFunnel.Add(new FunnelState()
                        {
                            Apex = m_apex, Left = m_leftPoint, Right = m_rightPoint
                        });
                    }
                }

                return(index + 1);
            }
            public void Calculate(MyPath <MyNavigationPrimitive> inputPath, List <Vector4D> refinedPath, ref Vector3 start, ref Vector3 end, int startIndex, int endIndex)
            {
                m_debugFunnel.Clear();
                m_debugPointsLeft.Clear();
                m_debugPointsRight.Clear();

                m_end               = end;
                m_endIndex          = endIndex;
                m_input             = inputPath;
                m_output            = refinedPath;
                m_apex              = start;
                m_funnelConstructed = false;
                m_segmentDangerous  = false;

                int i = startIndex;

                while (i < endIndex)
                {
                    i = AddTriangle(i);

                    if (i == endIndex)
                    {
                        PointTestResult result = TestPoint(end);
                        if (result == PointTestResult.LEFT)
                        {
                            m_apex = m_leftPoint;
                            m_funnelConstructed = false;
                            ConstructFunnel(m_leftIndex);
                            i = m_leftIndex + 1;
                        }
                        else if (result == PointTestResult.RIGHT)
                        {
                            m_apex = m_rightPoint;
                            m_funnelConstructed = false;
                            ConstructFunnel(m_rightIndex);
                            i = m_rightIndex + 1;
                        }

                        if (result == PointTestResult.INSIDE || i == endIndex)
                        {
                            AddPoint(ProjectEndOnTriangle(i));
                        }
                    }
                }

                if (startIndex == endIndex)
                {
                    AddPoint(ProjectEndOnTriangle(i));
                }

                m_input  = null;
                m_output = null;
            }
Exemple #3
0
 private int AddTriangle(int index)
 {
     if (!this.m_funnelConstructed)
     {
         this.ConstructFunnel(index);
     }
     else
     {
         Vector3 vector;
         Vector3 vector2;
         MyPath <MyNavigationPrimitive> .PathNode node = this.m_input[index];
         MyNavigationTriangle vertex = node.Vertex as MyNavigationTriangle;
         vertex.GetNavigationEdge(node.nextVertex);
         this.GetEdgeVerticesSafe(vertex, node.nextVertex, out vector, out vector2);
         PointTestResult result  = this.TestPoint(vector);
         PointTestResult result2 = this.TestPoint(vector2);
         if (result == PointTestResult.INSIDE)
         {
             this.NarrowFunnel(vector, index, true);
         }
         if (result2 == PointTestResult.INSIDE)
         {
             this.NarrowFunnel(vector2, index, false);
         }
         if (result == PointTestResult.RIGHT)
         {
             this.m_apex = this.m_rightPoint;
             this.m_funnelConstructed = false;
             this.ConstructFunnel(this.m_rightIndex + 1);
             return(this.m_rightIndex + 1);
         }
         if (result2 == PointTestResult.LEFT)
         {
             this.m_apex = this.m_leftPoint;
             this.m_funnelConstructed = false;
             this.ConstructFunnel(this.m_leftIndex + 1);
             return(this.m_leftIndex + 1);
         }
         if ((result == PointTestResult.INSIDE) || (result2 == PointTestResult.INSIDE))
         {
             MyNavigationMesh.FunnelState item = new MyNavigationMesh.FunnelState {
                 Apex  = this.m_apex,
                 Left  = this.m_leftPoint,
                 Right = this.m_rightPoint
             };
             MyNavigationMesh.m_debugFunnel.Add(item);
         }
     }
     return(index + 1);
 }
Exemple #4
0
            public void Calculate(MyPath <MyNavigationPrimitive> inputPath, List <Vector4D> refinedPath, ref Vector3 start, ref Vector3 end, int startIndex, int endIndex)
            {
                MyNavigationMesh.m_debugFunnel.Clear();
                MyNavigationMesh.m_debugPointsLeft.Clear();
                MyNavigationMesh.m_debugPointsRight.Clear();
                this.m_end               = end;
                this.m_endIndex          = endIndex;
                this.m_input             = inputPath;
                this.m_output            = refinedPath;
                this.m_apex              = start;
                this.m_funnelConstructed = false;
                this.m_segmentDangerous  = false;
                int index = startIndex;

                while (index < endIndex)
                {
                    index = this.AddTriangle(index);
                    if (index == endIndex)
                    {
                        PointTestResult result = this.TestPoint(end);
                        if (result == PointTestResult.LEFT)
                        {
                            this.m_apex = this.m_leftPoint;
                            this.m_funnelConstructed = false;
                            this.ConstructFunnel(this.m_leftIndex);
                            index = this.m_leftIndex + 1;
                        }
                        else if (result == PointTestResult.RIGHT)
                        {
                            this.m_apex = this.m_rightPoint;
                            this.m_funnelConstructed = false;
                            this.ConstructFunnel(this.m_rightIndex);
                            index = this.m_rightIndex + 1;
                        }
                        if ((result == PointTestResult.INSIDE) || (index == endIndex))
                        {
                            this.AddPoint(this.ProjectEndOnTriangle(index));
                        }
                    }
                }
                if (startIndex == endIndex)
                {
                    this.AddPoint(this.ProjectEndOnTriangle(index));
                }
                this.m_input  = null;
                this.m_output = null;
            }