Ejemplo n.º 1
0
        private static int FindLoopLocalMaximum(MyPolygon poly, int loop)
        {
            int index, maxIndex;
            Vector3 localMax;
            MyPolygon.Vertex vertex, otherVertex;

            index = poly.GetLoopStart(loop);
            poly.GetVertex(index, out vertex);

            maxIndex = index;
            localMax = vertex.Coord;

            // Find local maximum while going to the previous vertices in the loop
            index = vertex.Prev;
            poly.GetVertex(index, out otherVertex);
            while (otherVertex.Coord.Y > localMax.Y || (otherVertex.Coord.Y == localMax.Y && otherVertex.Coord.X > localMax.X))
            {
                maxIndex = index;
                localMax = otherVertex.Coord;
                index = otherVertex.Prev;
                poly.GetVertex(index, out otherVertex);
            }

            // Find local maximum while going to the next vertices in the loop
            index = vertex.Next;
            poly.GetVertex(index, out otherVertex);
            while (otherVertex.Coord.Y > localMax.Y || (otherVertex.Coord.Y == localMax.Y && otherVertex.Coord.X > localMax.X))
            {
                maxIndex = index;
                localMax = otherVertex.Coord;
                index = otherVertex.Next;
                poly.GetVertex(index, out otherVertex);
            }

            return maxIndex;
        }
Ejemplo n.º 2
0
        private static MatrixD DebugDrawBoundList(MatrixD drawMatrix, MyPolygon drawPoly, List<BoundPair> boundList)
        {
            foreach (var bound in boundList)
            {
                MyPolygon.Vertex v1, v2;
                Vector3 vec1 = default(Vector3);
                Vector3 vec2 = default(Vector3);

                int prev = bound.Left;
                drawPoly.GetVertex(prev, out v1);
                int current = v1.Prev;
                while (prev != bound.Minimum)
                {
                    drawPoly.GetVertex(current, out v2);

                    vec1 = Vector3.Transform(v1.Coord, drawMatrix);
                    vec2 = Vector3.Transform(v2.Coord, drawMatrix);

                    MyRenderProxy.DebugDrawLine3D(vec1, vec2, Color.Red, Color.Red, false);

                    prev = current;
                    v1 = v2;
                    current = v1.Prev;
                }

                MatrixD minimum = drawMatrix;
                minimum.Translation = vec2;
                MyRenderProxy.DebugDrawAxis(minimum, 0.25f, false);
                MyRenderProxy.DebugDrawSphere(vec2, 0.03f, Color.Yellow, 1.0f, false);

                prev = bound.Minimum;
                drawPoly.GetVertex(prev, out v1);
                current = v1.Prev;
                while (prev != bound.Right)
                {
                    drawPoly.GetVertex(current, out v2);

                    vec1 = Vector3.Transform(v1.Coord, drawMatrix);
                    vec2 = Vector3.Transform(v2.Coord, drawMatrix);

                    MyRenderProxy.DebugDrawLine3D(vec1, vec2, Color.Green, Color.Green, false);

                    prev = current;
                    v1 = v2;
                    current = v1.Prev;
                }

                if (bound.RightIsPrecededByHorizontal)
                {
                    MyRenderProxy.DebugDrawSphere(vec2, 0.03f, Color.Red, 1.0f, false);
                }
            }
            return drawMatrix;
        }
Ejemplo n.º 3
0
        private static void ConstructBoundPairs(MyPolygon poly, List<BoundPair> boundList)
        {
            for (int l = 0; l < poly.LoopCount; ++l)
            {
                int start, current, prev;
                MyPolygon.Vertex vertex;

                start = FindLoopLocalMaximum(poly, l);

                poly.GetVertex(start, out vertex);
                current = start;

                MyPolygon.Vertex otherVertex;
                poly.GetVertex(vertex.Prev, out otherVertex);

                BoundPair bounds = new BoundPair(poly, -1, -1, start, otherVertex.Coord.Y == vertex.Coord.Y);
                bool right = true;

                int comparison, prevComparison;
                comparison = -1;

                do
                {
                    Vector3 prevCoord = vertex.Coord;
                    prev = current;
                    current = vertex.Next;

                    poly.GetVertex(current, out vertex);
                    prevComparison = comparison;
                    comparison = CompareCoords(vertex.Coord, prevCoord);
                    Debug.Assert(comparison != 0, "Duplicate vertex in input polygon!");

                    if (right)
                    {
                        if (comparison > 0)
                        {
                            bounds.Minimum = prev;
                            right = false;
                        }
                    }
                    else
                    {
                        if (comparison < 0)
                        {
                            bounds.Left = prev;
                            Debug.Assert(bounds.IsValid());
                            boundList.Add(bounds);
                            bounds = new BoundPair(poly, -1, -1, prev, prevComparison == 0);
                            right = true;
                        }
                    }
                } while (current != start);

                bounds.Left = current;
                Debug.Assert(right == false);
                Debug.Assert(bounds.IsValid());
                boundList.Add(bounds);
            }
        }