11 {
12 s32 dummy[2];
13 Gfx* gfx = inGfx;
14 s32 readState;
15 f32 v1x, v1y, v1z;
16 f32 v2x, v2y, v2z;
17 f32 v3x, v3y, v3z;
18 f32 d12x, d12y, d12z;
19 f32 d32x, d32y, d32z;
20 f32 nx, ny, nz;
21 f32 norm;
22
23 Vtx_t* vtxArray;
24 u32 vtxCount;
25 s32 vtxEnd;
26 s32 i;
27
28 v1x = v1y = v1z = 0.0f;
29 v2x = v2y = v2z = 0.0f;
30 v3x = v3y = v3z = 0.0f;
31
32 while (TRUE) {
33 u32 w0 = gfx->words.w0;
34 u32 w1 = gfx->words.w1;
35 s32 op = w0 >> 24;
37 switch (op) {
38 case G_ENDDL:
40 break;
41 case G_DL:
43 break;
44 case G_VTX:
45 vtxCount = (w0 >> 0xC) & 0xFF;
46 vtxArray = (Vtx_t*) w1;
47 for (i = 0; i < vtxCount; i++) {
48 vtxEnd = (w0 >> 1) & 0x7F;
49 N(TriNormVertexBuffer)[(vtxEnd - vtxCount) + i] = &(vtxArray)[i];
50 }
51 break;
52 case G_TRI1:
53 v1x = N(TriNormVertexBuffer)[((w1 >> 16) & 0xFF) / 2]->ob[0];
54 v1y = N(TriNormVertexBuffer)[((w1 >> 16) & 0xFF) / 2]->ob[1];
55 v1z = N(TriNormVertexBuffer)[((w1 >> 16) & 0xFF) / 2]->ob[2];
56 v2x = N(TriNormVertexBuffer)[((w1 >> 8) & 0xFF) / 2]->ob[0];
57 v2y = N(TriNormVertexBuffer)[((w1 >> 8) & 0xFF) / 2]->ob[1];
58 v2z = N(TriNormVertexBuffer)[((w1 >> 8) & 0xFF) / 2]->ob[2];
59 v3x = N(TriNormVertexBuffer)[(w1 & 0xFF) / 2]->ob[0];
60 v3y = N(TriNormVertexBuffer)[(w1 & 0xFF) / 2]->ob[1];
61 v3z = N(TriNormVertexBuffer)[(w1 & 0xFF) / 2]->ob[2];
63 break;
64 case G_TRI2:
65 v1x = N(TriNormVertexBuffer)[((w0 >> 16) & 0xFF) / 2]->ob[0];
66 v1y = N(TriNormVertexBuffer)[((w0 >> 16) & 0xFF) / 2]->ob[1];
67 v1z = N(TriNormVertexBuffer)[((w0 >> 16) & 0xFF) / 2]->ob[2];
68 v2x = N(TriNormVertexBuffer)[((w0 >> 8) & 0xFF) / 2]->ob[0];
69 v2y = N(TriNormVertexBuffer)[((w0 >> 8) & 0xFF) / 2]->ob[1];
70 v2z = N(TriNormVertexBuffer)[((w0 >> 8) & 0xFF) / 2]->ob[2];
71 v3x = N(TriNormVertexBuffer)[(w0 & 0xFF) / 2]->ob[0];
72 v3y = N(TriNormVertexBuffer)[(w0 & 0xFF) / 2]->ob[1];
73 v3z = N(TriNormVertexBuffer)[(w0 & 0xFF) / 2]->ob[2];
75 break;
76 }
77
79 break;
80 }
81 gfx++;
82 }
83
85
86 d12x = v1x - v2x;
87 d12y = v1y - v2y;
88 d12z = v1z - v2z;
89 d32x = v3x - v2x;
90 d32y = v3y - v2y;
91 d32z = v3z - v2z;
92
93 nx = (d12y * d32z) - (d12z * d32y);
94 ny = (d12z * d32x) - (d12x * d32z);
95 nz = (d12x * d32y) - (d12y * d32x);
97 *outNx = nx / norm;
98 *outNy = ny / norm;
99 *outNz = nz / norm;
100 }
101}
void N GetFirstTriangleNormal(Gfx *inGfx, f32 *outNx, f32 *outNy, f32 *outNz)