Changeset 1173
 Timestamp:
 Oct 1, 2006, 1:53:35 PM (14 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/cucul/triangle.c
r1172 r1173 92 92 int x3, int y3, char const *str) 93 93 { 94 int x, y, xm ax, ymax;95 long int x a, xb, sl21, sl31, sl32;94 int x, y, xmin, xmax, ymin, ymax; 95 long int xx1, xx2, xa, xb, sl21, sl31, sl32; 96 96 uint32_t ch; 97 97 … … 114 114 x3 *= 0x1000; 115 115 116 xmax = cv>width  1; 117 ymax = cv>height  1; 116 ymin = y1 < 0 ? 0 : y1; 117 ymax = y3 + 1 < (int)cv>height ? y3 + 1 : (int)cv>height; 118 119 if(ymin < y2) 120 { 121 xa = x1 + sl21 * (ymin  y1); 122 xb = x1 + sl31 * (ymin  y1); 123 } 124 else if(ymin == y2) 125 { 126 xa = x2; 127 xb = (y1 == y3) ? x3 : x1 + sl31 * (ymin  y1); 128 } 129 else /* (ymin > y2) */ 130 { 131 xa = x3 + sl32 * (ymin  y3); 132 xb = x3 + sl31 * (ymin  y3); 133 } 118 134 119 135 /* Rasterize our triangle */ 120 for(y = y 1 < 0 ? 0 : y1; y <= y3 && y <=ymax; y++)136 for(y = ymin; y < ymax; y++) 121 137 { 122 if(y < y2) 138 /* Rescale xa and xb, recentering the division */ 139 if(xa < xb) 123 140 { 124 x a = x1 + sl21 * (y  y1);125 x b = x1 + sl31 * (y  y1);141 xx1 = (xa + 0x800) / 0x1000; 142 xx2 = (xb + 0x801) / 0x1000; 126 143 } 127 else if(y == y2)144 else 128 145 { 129 xa = x2; 130 xb = (y1 == y3) ? x3 : x1 + sl31 * (y  y1); 131 } 132 else /* (y > y2) */ 133 { 134 xa = x3 + sl32 * (y  y3); 135 xb = x3 + sl31 * (y  y3); 146 xx1 = (xb + 0x800) / 0x1000; 147 xx2 = (xa + 0x801) / 0x1000; 136 148 } 137 149 138 if(xb < xa) 139 { 140 long int tmp = xb; xb = xa; xa = tmp; 141 } 150 xmin = xx1 < 0 ? 0 : xx1; 151 xmax = xx2 + 1 < (int)cv>width ? xx2 + 1 : (int)cv>width; 142 152 143 /* Rescale xa and xb, recentering the division */ 144 xa = (xa + 0x800) / 0x1000; 145 xb = (xb + 0x801) / 0x1000; 153 for(x = xmin; x < xmax; x++) 154 cucul_putchar(cv, x, y, ch); 146 155 147 for(x = xa < 0 ? 0 : xa; x <= xb && x <= xmax; x++)148 cucul_putchar(cv, x, y, ch);156 xa += y < y2 ? sl21 : sl32; 157 xb += sl31; 149 158 } 150 159
Note: See TracChangeset
for help on using the changeset viewer.