コード例 #1
0
 private static void DrawLine(Core.CustomSpriteBatch g, Microsoft.Xna.Framework.Graphics.Texture2D sprPixel, Microsoft.Xna.Framework.Vector2 StartPos, Microsoft.Xna.Framework.Vector2 EndPos, Microsoft.Xna.Framework.Color DrawColor)
 {
     Microsoft.Xna.Framework.Vector2 ScaleFactor = new Microsoft.Xna.Framework.Vector2(EndPos.X - StartPos.X, EndPos.Y - StartPos.Y);
     ScaleFactor.Normalize();
     while ((int)StartPos.X != EndPos.X)
     {
         g.Draw(sprPixel, StartPos, DrawColor);
         StartPos += ScaleFactor;
     }
 }
コード例 #2
0
        public static void DisplayContour(Core.CustomSpriteBatch g, Microsoft.Xna.Framework.Graphics.Texture2D sprPixel,
                                          Contour2D FirstContour)          // Pointer to first contour
        {
            Vertex2D  P;
            Contour2D Q, PQ, IQ;

            Microsoft.Xna.Framework.Color DrawColor = Microsoft.Xna.Framework.Color.White;

            PQ = FirstContour;                                              // Start on first contour
            if (PQ != null)
            {
                IQ = PQ.inside_contours;
            }
            else
            {
                IQ = null;         // Fetch any inside contour
            }
            while (PQ != null)
            {                                                // While process contour valid
                if (IQ != null)
                {                                            // Check for inside contour
                    Q  = IQ;                                 // Set Q to inside contour
                    IQ = IQ.nextpeer;                        // Set IQ to next peer contour
                }
                else
                {                                                    // We have no inside contour
                    Q  = PQ;                                         // Set Q to this contour
                    PQ = PQ.nextpeer;                                // Set PQ to next peer contour
                    if (PQ != null)
                    {
                        IQ = PQ.inside_contours;
                    }
                    else
                    {
                        IQ = null; // Fetch any inside contour of that next peer
                    }
                }
                switch (Q.Direction)
                {                                                   // Contour direction will set colour
                case CONTOUR_DIR.CW_DIR:                            // CLOCK WISE CONTOUR
                    DrawColor = Microsoft.Xna.Framework.Color.Blue; // Blue pen
                    break;

                case CONTOUR_DIR.CCW_DIR:                            // COUNTER CLOCKWISE CONTOUR
                    DrawColor = Microsoft.Xna.Framework.Color.Red;   // Red pen
                    continue;                                        //Don't draw it as it's probably not useful

                case CONTOUR_DIR.UNKNOWN_DIR:                        // UNKNOWN DIRECTION CONTOUR
                    DrawColor = Microsoft.Xna.Framework.Color.Green; // Green pen
                    break;
                }

                P = Q.FirstVertex;                                          // Start on first vertex
                Microsoft.Xna.Framework.Vector2 StartPos = new Microsoft.Xna.Framework.Vector2((int)P.x, (int)P.y);
                Microsoft.Xna.Framework.Vector2 EndPos   = new Microsoft.Xna.Framework.Vector2();
                do
                {
                    P = P.next;        // Advance to next vertex pointer
                    if ((P.v_flags & 0x08) == 0)
                    {                  // Not a lift close move
                        EndPos.X = (int)P.x;
                        EndPos.Y = (int)P.y;
                        DrawLine(g, sprPixel, StartPos, EndPos, DrawColor);
                        StartPos.X = (int)P.x;
                        StartPos.Y = (int)P.y;
                    }
                }while (P != Q.FirstVertex);                               // Until we finish the loop
            }
        }