 Timestamp:
 Apr 16, 2010, 1:22:38 PM (9 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

libcaca/trunk/caca/triangle.c
r4369 r4389 165 165 float u3, float v3) 166 166 { 167 float y2y1, y3y1, y3y2; 168 float sl12, sl13, sl23; 169 float usl12, usl13, usl23, vsl12, vsl13, vsl23; 170 float xa, xb, ua, va, ub, vb, u, v; 167 171 uint32_t savedattr; 172 int tw, th, x, y, s; 168 173 169 174 #define SWAP_F(a, b) {float c = a; a = b; b = c; } … … 188 193 189 194 /* Clip texture coordinates */ 190 if (u1 < 0.0f) 191 u1 = 0.0f; 192 if (v1 < 0.0f) 193 v1 = 0.0f; 194 if (u2 < 0.0f) 195 u2 = 0.0f; 196 if (v2 < 0.0f) 197 v2 = 0.0f; 198 if (u3 < 0.0f) 199 u3 = 0.0f; 200 if (v3 < 0.0f) 201 v3 = 0.0f; 202 if (u1 > 1.0f) 203 u1 = 1.0f; 204 if (v1 > 1.0f) 205 v1 = 1.0f; 206 if (u2 > 1.0f) 207 u2 = 1.0f; 208 if (v2 > 1.0f) 209 v2 = 1.0f; 210 if (u3 > 1.0f) 211 u3 = 1.0f; 212 if (v3 > 1.0f) 213 v3 = 1.0f; 195 if (u1 < 0.0f) u1 = 0.0f; else if (u1 > 1.0f) u1 = 1.0f; 196 if (u2 < 0.0f) u2 = 0.0f; else if (u2 > 1.0f) u2 = 1.0f; 197 if (u3 < 0.0f) u3 = 0.0f; else if (u3 > 1.0f) u3 = 1.0f; 198 if (v1 < 0.0f) v1 = 0.0f; else if (v1 > 1.0f) v1 = 1.0f; 199 if (v2 < 0.0f) v2 = 0.0f; else if (v2 > 1.0f) v2 = 1.0f; 200 if (v3 < 0.0f) v3 = 0.0f; else if (v3 > 1.0f) v3 = 1.0f; 214 201 215 202 /* Convert relative tex coordinates to absolute */ 216 inttw = caca_get_canvas_width(tex);217 intth = caca_get_canvas_height(tex);203 tw = caca_get_canvas_width(tex); 204 th = caca_get_canvas_height(tex); 218 205 219 206 u1 *= (float)tw; … … 224 211 v3 *= (float)th; 225 212 226 int x, y; 227 float y2y1 = y2  y1; 228 float y3y1 = y3  y1; 229 float y3y2 = y3  y2; 213 y2y1 = (float)(y2  y1); 214 y3y1 = (float)(y3  y1); 215 y3y2 = (float)(y3  y2); 230 216 231 217 /* Compute slopes, making sure we don't divide by zero */ 232 218 /* (in this case, we don't need the value anyway) */ 233 219 /* FIXME : only compute needed slopes */ 234 floatsl12 = ((float)x2  x1) / (y2y1 == 0 ? 1 : y2y1);235 floatsl13 = ((float)x3  x1) / (y3y1 == 0 ? 1 : y3y1);236 floatsl23 = ((float)x3  x2) / (y3y2 == 0 ? 1 : y3y2);237 238 floatusl12 = (u2  u1) / (y2y1 == 0 ? 1 : y2y1);239 floatusl13 = (u3  u1) / (y3y1 == 0 ? 1 : y3y1);240 floatusl23 = (u3  u2) / (y3y2 == 0 ? 1 : y3y2);241 floatvsl12 = (v2  v1) / (y2y1 == 0 ? 1 : y2y1);242 floatvsl13 = (v3  v1) / (y3y1 == 0 ? 1 : y3y1);243 floatvsl23 = (v3  v2) / (y3y2 == 0 ? 1 : y3y2);244 245 float xa = (float)x1, xb= (float)x1;246 float ua = u1, ub = u1;247 float va = v1, vb = v1;248 float u, v;249 250 ints = 0;220 sl12 = ((float)x2  x1) / (y2y1 == 0 ? 1 : y2y1); 221 sl13 = ((float)x3  x1) / (y3y1 == 0 ? 1 : y3y1); 222 sl23 = ((float)x3  x2) / (y3y2 == 0 ? 1 : y3y2); 223 224 usl12 = (u2  u1) / (y2y1 == 0 ? 1 : y2y1); 225 usl13 = (u3  u1) / (y3y1 == 0 ? 1 : y3y1); 226 usl23 = (u3  u2) / (y3y2 == 0 ? 1 : y3y2); 227 vsl12 = (v2  v1) / (y2y1 == 0 ? 1 : y2y1); 228 vsl13 = (v3  v1) / (y3y1 == 0 ? 1 : y3y1); 229 vsl23 = (v3  v2) / (y3y2 == 0 ? 1 : y3y2); 230 231 xa = (float)x1; 232 xb = (float)x1; 233 ua = u1; ub = u1; 234 va = v1; vb = v1; 235 236 s = 0; 251 237 252 238 /* Top */ 253 239 for (y = y1; y < y2; y++) 254 240 { 241 float tus, tvs; 255 242 256 243 if (xb < xa) … … 265 252 } 266 253 267 floattus = (ub  ua) / (xb  xa);268 floattvs = (vb  va) / (xb  xa);254 tus = (ub  ua) / (xb  xa); 255 tvs = (vb  va) / (xb  xa); 269 256 v = va; 270 257 u = ua; … … 273 260 for (x = xa; x < xb; x++) 274 261 { 262 uint32_t attr, c; 275 263 u += tus; 276 264 v += tvs; 277 265 /* FIXME: use caca_get_canvas_attrs / caca_get_canvas_chars */ 278 uint32_tattr = caca_get_attr(tex, u, v);279 uint32_tc = caca_get_char(tex, u, v);266 attr = caca_get_attr(tex, u, v); 267 c = caca_get_char(tex, u, v); 280 268 caca_set_attr(cv, attr); 281 269 caca_put_char(cv, x, y, c); … … 317 305 for (y = y2; y < y3; y++) 318 306 { 307 float tus, tvs; 308 319 309 if (xb <= xa) 320 310 { … … 327 317 } 328 318 329 floattus = (ub  ua) / ((float)xb  xa);330 floattvs = (vb  va) / ((float)xb  xa);319 tus = (ub  ua) / ((float)xb  xa); 320 tvs = (vb  va) / ((float)xb  xa); 331 321 u = ua; 332 322 v = va; … … 335 325 for (x = xa; x < xb; x++) 336 326 { 327 uint32_t attr, c; 337 328 u += tus; 338 329 v += tvs; 339 330 /* FIXME, can be heavily optimised */ 340 uint32_tattr = caca_get_attr(tex, u, v);341 uint32_tc = caca_get_char(tex, u, v);331 attr = caca_get_attr(tex, u, v); 332 c = caca_get_char(tex, u, v); 342 333 caca_set_attr(cv, attr); 343 334 caca_put_char(cv, x, y, c);
Note: See TracChangeset
for help on using the changeset viewer.