subplane.c
5.53 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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/**************************************************************************
* *
* 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 "block.h"
#include "subplane.h"
int PlaneDivisions[2] = {0, 0};
int PlaneAxisPoints[2] = {0, 0};
int CurrentPlaneAxis = 0;
int NumPlanePolys = 2;
float PlaneDivisionArray[2][MAXPLANEAXISPOINTS];
Vtx Super_Planevtx[MAXPLANEVERTICES];
int PlaneVertexColor[8][3] =
{
0xff, 0, 0,
0, 0x7f, 0,
0, 0, 0xff,
0, 0, 0,
0, 0, 0xff,
0, 0, 0,
0xff, 0, 0,
0, 0x7f, 0,
};
float PlaneMinMax[2][2] =
{
20, 300,
-1500, -5
};
int NumPlaneVertices;
int NumSubPlanes;
struct PlaneVertexEntry
{
float Coordinates[2];
} PlaneVertexArray[MAXPLANEVERTICES];
struct SubPlaneEntry
{
int Index[4];
} SubPlaneArray[MAXSUBPLANES];
void CreatePlaneAxisDivisions(void)
{
int i, j;
for (i=0; i<2; i++)
{
PlaneAxisPoints[i] = 2 * (PlaneDivisions[i] + 1);
/* Fill out endpoints first */
PlaneDivisionArray[i][0] = PlaneMinMax[i][0];
PlaneDivisionArray[i][PlaneAxisPoints[i]-1] = PlaneMinMax[i][1];
for (j=0; j<PlaneDivisions[i]; j++)
{
PlaneDivisionArray[i][j*2+1] =
PlaneDivisionArray[i][j*2+2] =
(PlaneMinMax[i][0] +
(PlaneMinMax[i][1] - PlaneMinMax[i][0]) /
(PlaneDivisions[i] + 1.0) * (j+1.0));
}
}
}
void CreatePlaneVertexArray(void)
{
int i;
/* Now we compute the vertex array */
NumPlaneVertices = PlaneAxisPoints[0] * PlaneAxisPoints[1];
for (i=0; i<2*NumPlaneVertices; i++)
{
PlaneVertexArray[i/2].Coordinates[i%2] =
PlaneDivisionArray[i%2][(i%2==0) ? (i/2) % PlaneAxisPoints[0] :
(((i/2) / PlaneAxisPoints[0]) % PlaneAxisPoints[1])];
}
}
void KnitSubPlanes(void)
{
int i, j, k;
int PlaneIndexPointer, BaseVertex;
NumSubPlanes = NumPlaneVertices / 4;
PlaneIndexPointer = 0;
for (j=0; j<PlaneAxisPoints[1]; j+=2)
{
for (i=0; i<PlaneAxisPoints[0]; i+=2)
{
BaseVertex = j*PlaneAxisPoints[0] + i;
SubPlaneArray[PlaneIndexPointer].Index[0] = BaseVertex;
SubPlaneArray[PlaneIndexPointer].Index[1] = BaseVertex + 1;
SubPlaneArray[PlaneIndexPointer].Index[2] = BaseVertex + 1 + PlaneAxisPoints[0];
SubPlaneArray[PlaneIndexPointer].Index[3] = BaseVertex + PlaneAxisPoints[0];
PlaneIndexPointer++;
}
}
}
void CreatePlaneSuperVertices(void)
{
int VertexIndexPointer, i, j;
VertexIndexPointer = 0;
for (i=0; i<NumSubPlanes; i++)
{
for (j=0; j<4; j++)
{
V(Super_Planevtx + VertexIndexPointer,
(int) (PlaneVertexArray[SubPlaneArray[i].Index[j]].Coordinates[0] +
(PlaneVertexArray[SubPlaneArray[i].Index[j]].Coordinates[0] > 0 ? 0.5 : -0.5)),
20,
(int) (PlaneVertexArray[SubPlaneArray[i].Index[j]].Coordinates[1] +
(PlaneVertexArray[SubPlaneArray[i].Index[j]].Coordinates[1] > 0 ? 0.5 : -0.5)),
0,
((j==0) | (j==3)) ? (0 << 6) : (63 << 6),
((j==0) | (j==1)) ? (0 << 6) : (255 << 6),
PlaneVertexColor[j][0], PlaneVertexColor[j][1], PlaneVertexColor[j][2], 0xff);
VertexIndexPointer++;
}
}
}
void CreateSubPlanes(void)
{
CreatePlaneAxisDivisions();
CreatePlaneVertexArray();
KnitSubPlanes();
CreatePlaneSuperVertices();
}
void PlaneDL(int Offset)
{
gSP1Triangle(glistp++, Offset+2, Offset+1, Offset+0, Offset+2);
gSP1Triangle(glistp++, Offset+3, Offset+2, Offset+0, Offset+3);
}
void WriteSuperPlaneDisplayList(void)
{
int PlaneIndexPointer, i;
PlaneIndexPointer = 0;
/*
* The texture scaling parameters are .16 format. In order to
* get an exact texture scale of 1.0, we scale above by 2.0, and
* scale down here by 0.5
*/
for (i=0; i<NumSubPlanes/4 ; i++)
{
gSPVertex(glistp++, Super_Planevtx + i*16, 16, 0);
PlaneDL( 0);
PlaneDL( 4);
PlaneDL( 8);
PlaneDL(12);
PlaneIndexPointer += 4;
}
if (PlaneIndexPointer != NumSubPlanes)
{
if (NumSubPlanes - PlaneIndexPointer == 1)
{
gSPVertex(glistp++, Super_Planevtx + i*16, 4, 0);
PlaneDL(0);
}
else if (NumSubPlanes - PlaneIndexPointer == 2)
{
gSPVertex(glistp++, Super_Planevtx + i*16, 8, 0);
PlaneDL(0);
PlaneDL(4);
}
else
{
gSPVertex(glistp++, Super_Planevtx + i*16, 12, 0);
PlaneDL(0);
PlaneDL(4);
PlaneDL(8);
}
}
}
#include "brick.h"
void CreatePlanes(void)
{
if (!UseGlobalTransforms)
{
guTranslate(&dynamicp->TranslateIn, 0.0F, 0.0F, 0.0F);
gSPMatrix(glistp++, OS_K0_TO_PHYSICAL(&(dynamic.TranslateIn)),
G_MTX_MODELVIEW|G_MTX_LOAD|G_MTX_NOPUSH);
}
if (UseTextureMode) {
gDPLoadTextureBlock(glistp++, brick, G_IM_FMT_RGBA, G_IM_SIZ_16b,
32, 32, 0,
G_TX_WRAP | G_TX_NOMIRROR, G_TX_WRAP | G_TX_NOMIRROR,
5, 5, G_TX_NOLOD, G_TX_NOLOD);
}
WriteSuperPlaneDisplayList();
}