Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void DrawImage( )
- {
- POLYGON polyTempP, polyTempQ, polyTempQT; // Temporary polygons for copying transformed, projected / clipped
- // versions of scene polys before drawing them.
- int iCurrentPoly; // Current polygon in process
- if ( m_iNumOfPolys <= 0 )
- //DrawSquare(Default_Colour ); // This draws the square you see, replace with Trapezium, and later Polygon
- DrawTrapezium(Default_Colour, 50 + m_iMoveX, m_iMoveX, 0.5, -0.5, 200, 120 + m_iMoveY, m_iMoveY);
- else
- m_iOurFrameCount++; // Increment frame counter if we have a polygon to draw
- for ( iCurrentPoly = 0; iCurrentPoly < m_iNumOfPolys; iCurrentPoly++ ) // for each polygon
- {
- if ( iFaceSelection > m_iNumOfPolys )
- iFaceSelection = m_iNumOfPolys; //Keep debug selector in range
- if ( iFaceSelection && ( iCurrentPoly + 1 ) != iFaceSelection)
- continue; // Reject unselected polygons if debug selection active.
- polyTempP = polylist[iCurrentPoly]; //copy static data into temp poly structure
- // Copy each vertex in polygon, add displacement to allow shift
- for (int i = 0; i < polylist[iCurrentPoly].nv; i++)
- {
- polyTempP.vert[i].x = polylist[iCurrentPoly].vert[i].x + m_iMoveX;
- polyTempP.vert[i].y = polylist[iCurrentPoly].vert[i].y + m_iMoveY;
- }
- if ( bDebug )
- fprintf( debugfile, " number of vertices: %d\n", polyTempP.nv); // print number of vertices
- fflush( debugfile );
- if ( bDebug ) // Print out current poly specs if debug active
- {
- for (int i = 0; i < polyTempP.nv; i++)
- {
- fprintf( debugfile, "before clipping Polygon %d, Vertex %d values: %7.2f, %7.2f, %11.6f\n",
- iCurrentPoly, i, polyTempP.vert[i].x, polyTempP.vert[i].y, polyTempP.vert[i].z );
- }
- fflush( debugfile );
- }
- // The section below calls clipping and polygon draw routines, commented out to allow the
- // program to work without them. You may re-instate once you have appropriate routines,
- // or replace with your own code.
- /*
- ClipPolyXHigh( &polyTempP, &polyTempQT, WINDOWWIDTH ); // Clip against upper x boundary
- ClipPolyYHigh( &polyTempQT, &polyTempQ, WINDOWHEIGHT ); // Clip against upper y boundary (bottom of screen)
- ClipPolyXLow( &polyTempQ, &polyTempQT, 0); // Clip against lower x boundary
- ClipPolyYLow( &polyTempQT, &polyTempQ, 0); // Clip against lower y boundary (bottom of screen)
- if ( bDebug ) // Print out current poly specs if debug active
- {
- for ( int i = 0; i < polyTempQ.nv; i++ )
- fprintf( debugfile, "after clipping Polygon %d Vertex %d values:y %7.2f %7.2f %11.6f\n",
- iCurrentPoly, i, polyTempQ.vert[i].x, polyTempQ.vert[i].y, polyTempQ.vert[i].z );
- fflush(debugfile);
- }
- DrawPolygon( &polyTempQ ); // Call the drawing routine
- */
- }
- if ( m_iNumOfPolys > 0 )
- bDebug = false; // Switch debug off after first run - switch on again via keyboard control if needed
- }
- //-----------------------------------------------------------------------------
- // Name: DrawSquare
- // Desc: Draw a sqaure
- //-----------------------------------------------------------------------------
- //void DrawSquare(COLOUR c )
- 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)
- {
- //x_end = 50+m_iMoveX;
- //float x_end = 50 + m_iMoveX; //right slope
- //float x_start = m_iMoveX; //left slope
- //float slope_right =0.5;
- //float slope_left =-0.5;
- //int m_iMoveX = 200; //task 9
- //
- //float y_end = 120+ m_iMoveY;
- //float y_start = m_iMoveY;
- //Note no protection to keep in screen bounds...
- for ( int j = y_start; j < y_end; j++)
- //for ( int i = m_iMoveX; i < 50 + m_iMoveX; i++)
- {
- x_end = x_end + slope_right; //this line is so the float 'slope_right' can easily be changed to make the slope different
- x_start = x_start + slope_left;
- for ( int i =x_start; i < x_end; i++)
- //for( int j = m_iMoveY; j < 50 + m_iMoveY; j++)
- {
- Plotpix( i, j, c.r, c.g, c.b );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment