Recent Posts
PHP | 1 sec ago
None | 11 sec ago
MySQL | 41 sec ago
Bash | 51 sec ago
None | 1 min ago
None | 1 min ago
None | 2 min ago
None | 2 min ago
Java | 2 min ago
None | 2 min ago
Free Subdomains
Want a pastebin.com sub-domain for your community?
learn more...
What is pastebin?
Pastebin is a website that hosts all your text & code on dedicated servers for easy sharing.
learn more...
Learn a little bit about the new Pastebin.com on our help page. hide message
By Anonymous on the 9th of Feb 2010 10:52:52 PM Download | Raw | Embed | Report
  1. //-----------------------------------------------------------------------------
  2. // Name: ClipPolyYLow
  3. // Desc: Clipping Routine for lower y boundary
  4. //-----------------------------------------------------------------------------
  5. int ClipPolyYLow(POLYGON *pIinput, POLYGON *pOutput, int iYBound)
  6. {
  7.         // Tell calling routine how many vertices in pOutput array
  8.         return pOutput->nv;
  9. }
  10.  
  11. //-----------------------------------------------------------------------------
  12. // Name: ClipPolyXHi
  13. // Desc: Clipping Routine for upper x boundary
  14. //-----------------------------------------------------------------------------
  15. int ClipPolyXHigh(POLYGON *pIinput, POLYGON *pOutput, int iXBound)
  16. {
  17.         // Practical 4 - Define two local variables (2)
  18.         int current_vertex;
  19.         int previous_vertex;
  20.  
  21.         // Practical 4 - copy the non-vertex-related parts of the polygon from input to output (3)
  22.         pOutput->colour = pIinput->colour;
  23.  
  24.         // Practical 4 - Initialise the output number of vertices to zero (4)
  25.         pOutput->nv = 0;
  26.  
  27.         // Practical 4 - Implement the structured English algorithm given in the notes (5)
  28.         for (int current_vertex = 0; current_vertex < pIinput->nv; current_vertex++){
  29.                
  30.                 // Testing for wrap around (Practical 4 (5))
  31.                 if (current_vertex - 1 < 0){
  32.                         previous_vertex = (pIinput->nv - 1);
  33.                 }
  34.                 else if (current_vertex - 1 > 0){
  35.                         previous_vertex = current_vertex - 1;
  36.                 }
  37.  
  38.                 // Pracitcal 4 (6)
  39.                 // Check to see if current and previous are on screen
  40.                 if(pIinput->vert[previous_vertex].x <= iXBound){
  41.                         if(pIinput->vert[current_vertex].x <= iXBound){
  42.                                
  43.                                 // If this vertex on screen - copy this vertex to output
  44.                                 pOutput->vert[pOutput->nv] = pIinput->vert[current_vertex];
  45.                                 pOutput->nv++;
  46.                         }
  47.  
  48.                         else if(pIinput->vert[current_vertex].x > iXBound){
  49.                                
  50.                                 // If this vertex off screen - generate clipped vertex to output
  51.                                 // Output.x = xboundary
  52.                                 pOutput->vert[pOutput->nv].x = iXBound;
  53.                                 // output.y = current y + (x boundary - current x).(previous y - current y ) / (previous x - current x) (taken from notes)
  54.                                 pOutput->vert[pOutput->nv].y = pIinput->vert[current_vertex].y + (iXBound - pIinput->vert[current_vertex].x) * (pIinput->vert[previous_vertex].y - pIinput->vert[current_vertex].y)/ (pIinput->vert[previous_vertex].x - pIinput->vert[current_vertex].x);
  55.                                 pOutput->nv++;
  56.                         }
  57.                 }
  58.  
  59.                 else if (pIinput->vert[previous_vertex].x > iXBound){
  60.                         if (pIinput->vert[current_vertex].x <= iXBound){
  61.                                
  62.                                 // If this vertex off screen - generate clipped vertex to output
  63.                                 // Output.x = xboundary
  64.                                 pOutput->vert[pOutput->nv].x = iXBound;
  65.                                 // output.y = previous y + (x boundary - previous x).(current y - previous y ) / (cqurrent x - previous x) (taken from notes)
  66.                                 pOutput->vert[pOutput->nv].y = pIinput->vert[previous_vertex].y + (iXBound - pIinput->vert[previous_vertex].x) * (pIinput->vert[current_vertex].y - pIinput->vert[previous_vertex].y) / (pIinput->vert[current_vertex].x - pIinput->vert[previous_vertex].x);
  67.                                 pOutput->nv++;
  68.  
  69.                                 // Copy vertex to output
  70.                                 pOutput->vert[pOutput->nv] = pIinput->vert[current_vertex];
  71.                                 pOutput->nv++;
  72.                         }
  73.                 }
  74.  
  75.         }
  76.        
  77.         // Tell calling routine how many vertices in pOutput array
  78.         return pOutput->nv;
  79. }
Submit a correction or amendment below. Make A New Post
To highlight particular lines, prefix each line with @h@
Syntax highlighting:
Post expiration:
Post exposure:
Name / Title:
Email: