Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. int top_vertex = 0;
  2. int y_top, y_bottom;
  3. int num_verticies = p->nv;
  4. float slope_left, slope_right;
  5.  
  6. // Find 'top_vertex' by taking the LOWEST y co-or.
  7. for (int i = 1; i < num_verticies; i++)
  8. {
  9. if (p->vert[i].y < p->vert[top_vertex].y)
  10. {
  11. top_vertex = i;
  12. }
  13. }
  14.  
  15. int current_left = top_vertex;
  16. int current_right = top_vertex;
  17. int next_left = current_left - 1;
  18. int next_right = current_right + 1;
  19.  
  20. // Test for wrap
  21. if (next_left < 0)
  22. {
  23. next_left = num_verticies - 1;
  24. }
  25. if (next_right >= num_verticies)
  26. {
  27. next_right = 0;
  28. }
  29.  
  30. // Calculate left and right slopes
  31. float y_dif_R, y_dif_L;
  32.  
  33. y_dif_L = (p->vert[next_left].y - p->vert[current_left].y);
  34. y_dif_R = (p->vert[next_right].y - p->vert[current_right].y);
  35.  
  36. if ( (y_dif_L != 0) || (y_dif_R != 0) )
  37. {
  38. slope_left = (p->vert[next_left].x - p->vert[current_left].x) / y_dif_L;
  39. slope_right = (p->vert[next_right].x - p->vert[current_right].x) / y_dif_R;
  40. }
  41.  
  42. //Check which side the trapezium finishes first
  43.  
  44. if (p->vert[next_left].y < p->vert[next_right].y)
  45. {
  46. y_bottom = p->vert[next_left].y;
  47. }
  48. else
  49. {
  50. y_bottom = p->vert[next_right].y;
  51. }
  52.  
  53. // Call Function
  54.  
  55. y_top = p->vert[top_vertex].y;
  56.  
  57. float x_start = p->vert[current_left].x;
  58. float x_end = p->vert[current_right].x;
  59.  
  60. //DrawSquare(Default_Colour, 100, 200, -0.5, 1.5, 100, 160);
  61. DrawSquare(p->colour, x_start, x_end, slope_left, slope_right, y_bottom, y_top);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement