]> git.wh0rd.org - ICEs.git/blob - 394889/s_triangle.i.17
more
[ICEs.git] / 394889 / s_triangle.i.17
1 static __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
11 static 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] ?
43 ((vMid[4][0] * (float)2048) + 0.5F) :
44 ((vMid[4][0] * (float)2048) - 0.5F);
45 eMaj.dx = (vMax_fx - vMin_fx) * (1.0F / (float)2048);
46 eMaj.dy = (vMax_fy - vMin_fy) * (1.0F / (float)2048);
47 eTop.dx = (vMax_fx - vMid_fx) * (1.0F / (float)2048);
48 eBot.dy = (vMid_fy - vMin_fy) * (1.0F / (float)2048);
49 float area = eMaj.dx * eBot.dy - eBot.dx * eMaj.dy;
50 if (IS_INF_OR_NAN(area))
51 return;
52 oneOverArea = 1.0F / area;
53 eBot.fx0 = vMin_fx;
54 int scan_from_left_to_right;
55 void (*PutRowRGB)();
56 float eMaj_ds = (vMax[4][0] - vMin[4][0]);
57 float eBot_ds;
58 float stepx =
59 oneOverArea * (eMaj_ds * eBot.dy - eMaj.dy * eBot_ds);
60 int step = (stepx >= 0.0F) ? stepx : (stepx * (float)2048) - 0.5F;
61 int subTriangle;
62 int fxRightEdge = 0;
63 for (subTriangle = 0; subTriangle <= 1; subTriangle++) {
64 EdgeT *eRight;
65 int lines;
66 if (subTriangle == 0) {
67 if (scan_from_left_to_right) {
68 eRight = &eBot;
69 lines = eRight->lines;
70 } else {
71 eRight = &eMaj;
72 }
73 } else {
74 if (scan_from_left_to_right) {
75 eRight = &eTop;
76 }
77 fxRightEdge = eRight->fsx;
78 }
79 while (lines > 0) {
80 int end; int x; int y;
81 x = 0;
82 if (fxRightEdge <= x)
83 end = 0;
84 else
85 end = fxRightEdge - x;
86 if (end > 0 && y >= 0) {
87 int i;
88 char *rgb;
89 for (i = 0; i < end; i++) {
90 int it;
91 char *texture;
92 rgb[i] = texture[it];
93 it += step;
94 }
95 PutRowRGB(rgb);
96 }
97 }
98 }
99 }
100
101 void *foo()
102 {
103 return simple_textured_triangle;
104 }