tris.c
2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#include <ultra64.h>
#include "fill.h"
unsigned int xseed = (7789<<16)+13399;
unsigned int xrand(void)
{
unsigned int x;
x = (xseed<<2) + 2;
x *= (x+1);
x = x >> 2;
xseed = x;
return( x );
}
float frand(void)
{
return((xrand()%32767) / 32768.0);
}
/*
* Create list of randomly placed triangles, with a certain aspect ratio
* and a certain area. The aspect ratio is defined as the longest x edge
* divided by the longest y edge. The triangle always has the general shape:
*
* (x0,y0)
* +------------+(x1,y1)
* | /
* | /
* | /
* | /
* | /
* | /
* + (x2,y2)
*
* Note that triangles are defined in 8b coordinates so they have twice
* the size of 4-bit triangles in the X direction.
*
*/
void
makeTriList(int ntri, float area , float aspect)
{
int tri;
float xl, yl;
float x0, y0, z0;
float x1, y1, z1;
float x2, y2, z2;
float tc;
Gfx *tlistp = dynamicp->trilist;
yl = sqrtf(2.0*area/aspect);
xl = yl*aspect;
/* account for 4-bit pixel size in X direction */
xl /= 2;
for(tri = 0; tri < ntri; tri++) {
do {
x0 = SCREEN_WD/2 * frand();
y0 = SCREEN_HT * frand();
} while (((x0+xl) > SCREEN_WD/2) || ((y0+yl) > SCREEN_HT));
x1 = x0 + xl;
y1 = y0;
x2 = x0;
y2 = y0 + yl;
z0 = 500.0 * frand() + 10.0;
z1 = 500.0 * frand() + 10.0;
z2 = 500.0 * frand() + 10.0;
V(&(dynamic.vtxlist[tri * 3]), (s16)x0, (s16)y0, (s16)z0, 0,
(s16)(x0 * 64), (s16)(y0 * 64),
0xff, 0xff, 0xff, 0xff);
V(&(dynamic.vtxlist[tri*3+1]), (short)x1, (short)y1, (short)z1, 0,
(s16)(x1 * 64), (s16)(y1 * 64),
0xff, 0xff, 0xff, 0xff);
V(&(dynamic.vtxlist[tri*3+2]), (short)x2, (short)y2, (short)z2, 0,
(s16)(x2 * 64), (s16)(y2 * 64),
0xff, 0xff, 0xff, 0xff);
/* assign random index for color */
tc = 255.0 * frand();
if(DoPrimMode) {
gDPSetPrimColor(tlistp++, 0, 0, (u8)tc, (u8)tc, (u8)tc, (u8)tc);
}
gSPVertex(tlistp++, &dynamic.vtxlist[tri*3], 3, 0);
gSP1Triangle(tlistp++, 0, 1, 2, 0);
}
gSPEndDisplayList(tlistp++);
}