Guest User

DrawTrapezium

a guest
Jan 25th, 2012
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.99 KB | None | 0 0
  1. void DrawImage( )
  2. {
  3.     POLYGON polyTempP, polyTempQ, polyTempQT;   // Temporary polygons for copying transformed, projected / clipped
  4.                                                 // versions of scene polys before drawing them.
  5.     int iCurrentPoly;                           // Current polygon in process
  6.    
  7.     if ( m_iNumOfPolys <= 0 )
  8.         //DrawSquare(Default_Colour );      // This draws the square you see, replace with Trapezium, and later Polygon
  9.      DrawTrapezium(Default_Colour, 50 + m_iMoveX, m_iMoveX, 0.5, -0.5, 200, 120 + m_iMoveY, m_iMoveY);
  10.     else
  11.         m_iOurFrameCount++; // Increment frame counter if we have a polygon to draw
  12.  
  13.     for ( iCurrentPoly = 0; iCurrentPoly < m_iNumOfPolys; iCurrentPoly++ )  // for each polygon
  14.     {
  15.         if ( iFaceSelection > m_iNumOfPolys )
  16.             iFaceSelection = m_iNumOfPolys;    //Keep debug selector in range
  17.        
  18.        
  19.         if ( iFaceSelection && ( iCurrentPoly + 1 ) != iFaceSelection)
  20.             continue; // Reject unselected polygons if debug selection active.
  21.        
  22.    
  23.         polyTempP = polylist[iCurrentPoly];             //copy static data into temp poly structure
  24.        
  25.         // Copy each vertex in polygon, add displacement to allow shift
  26.         for (int i = 0; i < polylist[iCurrentPoly].nv; i++)
  27.         {
  28.             polyTempP.vert[i].x = polylist[iCurrentPoly].vert[i].x + m_iMoveX;
  29.             polyTempP.vert[i].y = polylist[iCurrentPoly].vert[i].y + m_iMoveY;
  30.         }
  31.                
  32.         if ( bDebug )
  33.             fprintf( debugfile, " number of vertices: %d\n", polyTempP.nv);   // print number of vertices
  34.  
  35.         fflush( debugfile );
  36.        
  37.         if ( bDebug )   // Print out current poly specs if debug active
  38.         {
  39.             for (int i = 0; i < polyTempP.nv; i++)
  40.             {
  41.                 fprintf( debugfile, "before clipping Polygon %d, Vertex %d values: %7.2f, %7.2f, %11.6f\n",
  42.                          iCurrentPoly, i, polyTempP.vert[i].x, polyTempP.vert[i].y, polyTempP.vert[i].z );
  43.             }
  44.             fflush( debugfile );
  45.            
  46.         }
  47.         // The section below calls clipping and polygon draw routines, commented out to allow the
  48.         // program to work without them. You may re-instate once you have appropriate routines,
  49.         // or replace with your own code.
  50.         /*
  51.         ClipPolyXHigh( &polyTempP, &polyTempQT, WINDOWWIDTH );  // Clip against upper x boundary
  52.         ClipPolyYHigh( &polyTempQT, &polyTempQ, WINDOWHEIGHT ); // Clip against upper y boundary (bottom of screen)
  53.         ClipPolyXLow( &polyTempQ, &polyTempQT, 0);              // Clip against lower x boundary
  54.         ClipPolyYLow( &polyTempQT, &polyTempQ, 0);              // Clip against lower y boundary (bottom of screen)
  55.        
  56.         if ( bDebug )   // Print out current poly specs if debug active
  57.         {
  58.             for ( int i = 0; i < polyTempQ.nv; i++ )
  59.                 fprintf( debugfile, "after clipping Polygon %d Vertex %d values:y %7.2f  %7.2f %11.6f\n",
  60.                          iCurrentPoly, i, polyTempQ.vert[i].x, polyTempQ.vert[i].y, polyTempQ.vert[i].z );
  61.  
  62.             fflush(debugfile);
  63.         }
  64.          
  65.         DrawPolygon( &polyTempQ );  // Call the drawing routine
  66.         */
  67.     }
  68.     if ( m_iNumOfPolys > 0 )
  69.         bDebug = false; // Switch debug off after first run - switch on again via keyboard control if needed
  70.  
  71.    
  72. }
  73.  
  74. //-----------------------------------------------------------------------------
  75. // Name: DrawSquare
  76. // Desc: Draw a sqaure
  77. //-----------------------------------------------------------------------------
  78. //void DrawSquare(COLOUR c )
  79. void DrawTrapezium( COLOUR c , float x_end, float x_start, float slope_right, float slope_left, int m_iMoveX, float y_end, float y_start)
  80. {
  81.     //x_end = 50+m_iMoveX;
  82.     //float x_end = 50 + m_iMoveX; //right slope
  83.     //float x_start = m_iMoveX; //left slope
  84.     //float slope_right =0.5;
  85.     //float slope_left =-0.5;
  86.     //int m_iMoveX = 200; //task 9
  87.     //
  88.     //float y_end = 120+ m_iMoveY;
  89.     //float y_start = m_iMoveY;
  90.  
  91.     //Note no protection to keep in screen bounds...
  92.     for ( int j = y_start; j < y_end; j++)
  93.     //for ( int i = m_iMoveX; i < 50 + m_iMoveX; i++)
  94.     {
  95.         x_end = x_end + slope_right; //this line is so the float 'slope_right' can easily be changed to make the slope different
  96.         x_start = x_start + slope_left;
  97.         for ( int i =x_start; i < x_end; i++)
  98.         //for( int j = m_iMoveY; j < 50 + m_iMoveY; j++)
  99.         {
  100.  
  101.             Plotpix( i, j, c.r, c.g, c.b );
  102.         }
  103.     }  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment