X-Git-Url: https://git.wh0rd.org/?p=ICEs.git;a=blobdiff_plain;f=394889%2Fs_triangle.i;fp=394889%2Fs_triangle.i;h=a18c13fe237e675844c2e5df81bf79fbc50dec0c;hp=0000000000000000000000000000000000000000;hb=bd3239d2bbe0de3a200b266503e3330b1e391489;hpb=dbff64cb4b7530861c2309c794efdd4e0cf47a23 diff --git a/394889/s_triangle.i b/394889/s_triangle.i new file mode 100644 index 0000000..a18c13f --- /dev/null +++ b/394889/s_triangle.i @@ -0,0 +1,103 @@ +static __inline__ int IS_INF_OR_NAN(float x) +{ + union { + float f; + int i; + } tmp; + tmp.f = x; + return tmp.i; +} + +static void simple_textured_triangle(float **v1) +{ + float **v0; + float **v2; + typedef struct { + float dx; + float dy; + int fsx; + int fx0; + int lines; + } EdgeT; + EdgeT eMaj; + EdgeT eTop; + EdgeT eBot; + float oneOverArea; + float **vMin; + float **vMid; + float **vMax; + int vMin_fx; + int vMin_fy; + int vMid_fx; + int vMid_fy; + int vMax_fx; + int vMax_fy; + if (v1[0][1] <= v2[0][1]) { + vMin = v0; + vMax = v1; + vMin_fy = v0[0][1]; + } + vMin_fx = vMin[0][0]; + vMid_fx = + vMid[4][0] ? ((vMid[4][0] * (float)2048) + + 0.5F) : ((vMid[4][0] * (float)2048) - 0.5F); + eMaj.dx = (vMax_fx - vMin_fx) * (1.0F / (float)2048); + eMaj.dy = (vMax_fy - vMin_fy) * (1.0F / (float)2048); + eTop.dx = (vMax_fx - vMid_fx) * (1.0F / (float)2048); + eBot.dy = (vMid_fy - vMin_fy) * (1.0F / (float)2048); + float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy; + if (IS_INF_OR_NAN(area)) + return; + oneOverArea = 1.0F / area; + eBot.fx0 = vMin_fx; + int scan_from_left_to_right; + float eMaj_ds = (vMax[4][0] - vMin[4][0]); + float eBot_ds; + float stepx = oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds); + int step = (stepx >= 0.0F) ? stepx : (stepx * (float)2048) - 0.5F; + int subTriangle; + int fxRightEdge = 0; + for (subTriangle = 0; subTriangle <= 1; subTriangle++) { + EdgeT *eRight; + int lines; + if (subTriangle == 0) { + if (scan_from_left_to_right) { + eRight = &eBot; + lines = eRight->lines; + } else { + eRight = &eMaj; + } + } else { + if (scan_from_left_to_right) { + eRight = &eTop; + } + fxRightEdge = eRight->fsx; + } + while (lines > 0) { + int end; + int x; + int y; + x = 0; + if (fxRightEdge <= x) + end = 0; + else + end = fxRightEdge - x; + if (end > 0 && y >= 0) { + int i; + char *rgb; + for (i = 0; i < end; i++) { + int it; + char *texture; + rgb[i] = texture[it]; + it += step; + } + PutRowRGB(rgb); + } + } + } +} + +void *foo() +{ + return simple_textured_triangle; +}