tris.c
1.62 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
#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)
*/
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;
Gfx *tlistp = dynamicp->trilist;
yl = sqrtf(2.0*area/aspect);
xl = yl*aspect;
for(tri = 0; tri < ntri; tri++) {
do {
x0 = SCREEN_WD * frand();
y0 = SCREEN_HT * frand();
} while (((x0+xl) > SCREEN_WD) || ((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]), (short)x0, (short)y0, (short)z0, 0, 0, 0,
0xff, 0xff, 0xff, 0xff);
V(&(dynamic.vtxlist[tri*3+1]), (short)x1, (short)y1, (short)z1, 0, 0, 0,
0xff, 0xff, 0xff, 0xff);
V(&(dynamic.vtxlist[tri*3+2]), (short)x2, (short)y2, (short)z2, 0, 0, 0,
0xff, 0xff, 0xff, 0xff);
gSPVertex(tlistp++, &dynamic.vtxlist[tri*3], 3, 0);
gSP1Triangle(tlistp++, 0, 1, 2, 0);
}
gSPEndDisplayList(tlistp++);
}