]> git.wh0rd.org - ICEs.git/blame - 394889/s_triangle.i
more
[ICEs.git] / 394889 / s_triangle.i
CommitLineData
bd3239d2
MF
1static __inline__ int IS_INF_OR_NAN(float x)
2{
3 union {
4 float f;
5 int i;
6 } tmp;
7 tmp.f = x;
8 return tmp.i;
9}
10
11static void simple_textured_triangle(float **v1)
12{
13 float **v0;
14 float **v2;
15 typedef struct {
16 float dx;
17 float dy;
18 int fsx;
19 int fx0;
20 int lines;
21 } EdgeT;
22 EdgeT eMaj;
23 EdgeT eTop;
24 EdgeT eBot;
25 float oneOverArea;
26 float **vMin;
27 float **vMid;
28 float **vMax;
29 int vMin_fx;
30 int vMin_fy;
31 int vMid_fx;
32 int vMid_fy;
33 int vMax_fx;
34 int vMax_fy;
35 if (v1[0][1] <= v2[0][1]) {
36 vMin = v0;
37 vMax = v1;
38 vMin_fy = v0[0][1];
39 }
40 vMin_fx = vMin[0][0];
41 vMid_fx =
42 vMid[4][0] ? ((vMid[4][0] * (float)2048) +
43 0.5F) : ((vMid[4][0] * (float)2048) - 0.5F);
44 eMaj.dx = (vMax_fx - vMin_fx) * (1.0F / (float)2048);
45 eMaj.dy = (vMax_fy - vMin_fy) * (1.0F / (float)2048);
46 eTop.dx = (vMax_fx - vMid_fx) * (1.0F / (float)2048);
47 eBot.dy = (vMid_fy - vMin_fy) * (1.0F / (float)2048);
48 float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
49 if (IS_INF_OR_NAN(area))
50 return;
51 oneOverArea = 1.0F / area;
52 eBot.fx0 = vMin_fx;
53 int scan_from_left_to_right;
54 float eMaj_ds = (vMax[4][0] - vMin[4][0]);
55 float eBot_ds;
56 float stepx = oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds);
57 int step = (stepx >= 0.0F) ? stepx : (stepx * (float)2048) - 0.5F;
58 int subTriangle;
59 int fxRightEdge = 0;
60 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
61 EdgeT *eRight;
62 int lines;
63 if (subTriangle == 0) {
64 if (scan_from_left_to_right) {
65 eRight = &eBot;
66 lines = eRight->lines;
67 } else {
68 eRight = &eMaj;
69 }
70 } else {
71 if (scan_from_left_to_right) {
72 eRight = &eTop;
73 }
74 fxRightEdge = eRight->fsx;
75 }
76 while (lines > 0) {
77 int end;
78 int x;
79 int y;
80 x = 0;
81 if (fxRightEdge <= x)
82 end = 0;
83 else
84 end = fxRightEdge - x;
85 if (end > 0 && y >= 0) {
86 int i;
87 char *rgb;
88 for (i = 0; i < end; i++) {
89 int it;
90 char *texture;
91 rgb[i] = texture[it];
92 it += step;
93 }
94 PutRowRGB(rgb);
95 }
96 }
97 }
98}
99
100void *foo()
101{
102 return simple_textured_triangle;
103}