Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int top_vertex = 0;
- int y_top, y_bottom;
- int num_verticies = p->nv;
- float slope_left, slope_right;
- // Find 'top_vertex' by taking the LOWEST y co-or.
- for (int i = 1; i < num_verticies; i++)
- {
- if (p->vert[i].y < p->vert[top_vertex].y)
- {
- top_vertex = i;
- }
- }
- int current_left = top_vertex;
- int current_right = top_vertex;
- int next_left = current_left - 1;
- int next_right = current_right + 1;
- // Test for wrap
- if (next_left < 0)
- {
- next_left = num_verticies - 1;
- }
- if (next_right >= num_verticies)
- {
- next_right = 0;
- }
- // Calculate left and right slopes
- float y_dif_R, y_dif_L;
- y_dif_L = (p->vert[next_left].y - p->vert[current_left].y);
- y_dif_R = (p->vert[next_right].y - p->vert[current_right].y);
- if ( (y_dif_L != 0) || (y_dif_R != 0) )
- {
- slope_left = (p->vert[next_left].x - p->vert[current_left].x) / y_dif_L;
- slope_right = (p->vert[next_right].x - p->vert[current_right].x) / y_dif_R;
- }
- //Check which side the trapezium finishes first
- if (p->vert[next_left].y < p->vert[next_right].y)
- {
- y_bottom = p->vert[next_left].y;
- }
- else
- {
- y_bottom = p->vert[next_right].y;
- }
- // Call Function
- y_top = p->vert[top_vertex].y;
- float x_start = p->vert[current_left].x;
- float x_end = p->vert[current_right].x;
- //DrawSquare(Default_Colour, 100, 200, -0.5, 1.5, 100, 160);
- 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