randtri.c
3.81 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
/**************************************************************************
* *
* Copyright (C) 1995, Silicon Graphics, Inc. *
* *
* These coded instructions, statements, and computer programs contain *
* unpublished proprietary information of Silicon Graphics, Inc., and *
* are protected by Federal copyright law. They may not be disclosed *
* to third parties or copied or duplicated in any form, in whole or *
* in part, without the prior written consent of Silicon Graphics, Inc. *
* *
*************************************************************************/
#include <ultra64.h>
#include <PR/ramrom.h> /* needed for argument passing into the app */
#include <assert.h>
#include "rtmonky.h"
void rand_tri( Vtx_t * );
int xrand( void );
#define BIG_RTS
#ifdef BIG_RTS
#define BOXX (10799)
#define BOXY (13399)
#else
#define BOXX (107)
#define BOXY (131)
#endif
/* Both are prime and so is the result! */
#define GOOD_SEED ((7789<<16)+13399)
unsigned int xseed = 174823885;
void
randtri( Gfx **pglistp, Dynamic *dynamicp, int num )
{
Vtx *vcur;
Gfx *gcur;
Gfx *glistp;
int i;
glistp = *pglistp;
vcur = &(dynamicp->vtlist[0]);
gcur = &(dynamicp->gtlist[0]);
gSPDisplayList(glistp++, gcur);
gDPPipeSync(gcur++ );
gSPClearGeometryMode(gcur++, G_ZBUFFER);
gSPClearGeometryMode(gcur++, G_CULL_BACK);
gSPClearGeometryMode(gcur++, G_CULL_FRONT);
gSPSetGeometryMode(gcur++, G_SHADE);
gDPSetCombineMode (gcur++, G_CC_SHADE, G_CC_SHADE);
for(i=0;i<num;i++) {
rand_tri( &(vcur->v) );
gSPVertex(gcur++, &(vcur->v), 3, 0);
gSP1Triangle(gcur++, 0, 1, 2, 0);
vcur+= 3;
};
gSPEndDisplayList( gcur++ );
*pglistp = glistp;
}
#ifdef SHOW_NUMS
void font_show_num( Gfx **, int, int, int );
if( (count & 0x00) == 0 ) {
font_show_num( &glistp, 100, 100, count );
font_show_num( &glistp, 100, 200, xseed );
}
count ++;
}
#endif
#define K64 (65536)
#define R(y) (xrand()%y)
void
rand_tri( Vtx_t *vp )
{
int x,y;
int x1,y1;
int x2,y2;
int dx,dy;
int base2, hscale;
int rb, rh;
x1 = vp->ob[0] = R(BOXX);
y1 = vp->ob[1] = R(BOXY);
vp->ob[2] = 0;
vp->flag = 0;
vp->tc[0] = 0;
vp->tc[1] = 0;
vp->cn[0] = R(255);
vp->cn[1] = R(255);
vp->cn[2] = R(255);
vp->cn[3] = R(255);
vp++;
x2 = vp->ob[0] = R(BOXX);
y2 = vp->ob[1] = R(BOXY);
vp->ob[2] = 0;
vp->flag = 0;
vp->tc[0] = 0;
vp->tc[1] = 0;
vp->cn[0] = R(255);
vp->cn[1] = R(255);
vp->cn[2] = R(255);
vp->cn[3] = R(255);
vp++;
dx = x2 - x1;
dy = y2 - y1;
base2 = (dx*dx+dy*dy + 32) >> 6;
if( base2 < 2 )
base2 = 1;
#define MAX_AREA (BOXX*BOXY)
hscale = MAX_AREA/base2;
/* emPrintf("dx=%d, dy=%d, hscale=%d/64K (%g)\n", dx, dy, hscale, hscale/65536.0 ); */
rb = R(K64);
rh = R(hscale);
x = x1 + ((dx*rb + K64/2)>>16) + ((dy*rh + K64/2)>>16);
y = y1 + ((dy*rb + K64/2)>>16) - ((dx*rh + K64/2)>>16);
if( (y2 > y1) && (y > y2) )
y = y2;
else if( (y1 > y2) && (y > y1) )
y = y1;
if( (y2 < y1) && (y < y2) )
y = y2;
else if( (y1 < y2) && (y < y1) )
y = y1;
if( x <= 0 )
x = 1;
else if( x >= BOXX )
x = BOXX-1;
vp->ob[0] = x;
vp->ob[1] = y;
vp->ob[2] = -5;
vp->flag = 0;
vp->tc[0] = 0;
vp->tc[1] = 0;
vp->cn[0] = R(255);
vp->cn[1] = R(255);
vp->cn[2] = R(255);
vp->cn[3] = R(255);
}
int xrand( void )
{
unsigned int x;
x = (xseed<<2) + 2;
x *= (x+1);
x = x >> 2;
xseed = x;
return( x );
}