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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
|
/* Treeki's 3D Library for Wii */
#include "3dlib/treeki3d.h"
#include <game.h>
#include "rvl/PPCWGPipe.h"
#include "rvl/GXVert.h"
namespace T3D {
const GXColor Black = {0,0,0,255};
const GXColor White = {255,255,255,255};
u32 HasBeenInited;
RenderInfo *RenderQueue;
int RenderQueuePos;
CameraInfo Camera;
tmdl_material *LastMaterial;
int tmdl_header_sizes[] = {0, 0, sizeof(tmdl_headerv2), sizeof(tmdl_header)};
bool Init(bool test) {
if (HasBeenInited == 'T3Df')
return test;
HasBeenInited = 'T3Df';
OSReport("T3D Engine revision 3 -- created by Treeki\n");
OSReport("Setting up the render queue for %d model(s).\n", OBJ_COUNT);
RenderQueue = new RenderInfo[OBJ_COUNT];
RenderQueuePos = 0;
// Setup camera
Camera.projection = GX_PERSPECTIVE;
GXRenderModeObj *rm = Hook_GetGXRenderModeObj();
f32 aspect = (f32)rm->viWidth / (f32)rm->viHeight;
OSReport("Dump of GXRenderModeObj settings:\n");
OSReport("viTVmode => %d; fbWidth => %d; efbHeight => %d; xfbHeight => %d\n", rm->viTVmode, rm->fbWidth, rm->efbHeight, rm->xfbHeight);
OSReport("viXOrigin => %d; viYOrigin => %d; viWidth => %d; viHeight => %d\n", rm->viXOrigin, rm->viYOrigin, rm->viWidth, rm->viHeight);
OSReport("xFBmode => %d; field_rendering => %d; aa => %d\n", rm->xFBmode, rm->field_rendering, rm->aa);
OSReport("Calculated VI aspect: %f\n", aspect);
MTXPerspective(Camera.projection_matrix, 45, aspect, 0.1f, 2400.0f);
Point3d camPos = {0,0,-150};
Vec camUp = {0,1,0};
Point3d target = {0,0,0};
MTXLookAt(Camera.view_matrix, &camPos, &camUp, &target);
return test;
}
bool Model::bind(void *data, const char *mdlname) {
ARCHandle arc;
ARCFileInfo model_info;
tmdl_header *model = 0;
OSReport("[T3D] Loading model %s\n", mdlname);
// obtain the files from the arc
char model_name[64];
snprintf(model_name, 64, "t3d/mdl_%s.tmdl", mdlname);
if (!ARCInitHandle(data, &arc)) {
OSReport("[T3D] CANNOT LOAD ARC!!\n");
OSReport("ARCInitHandle returned false\n");
return false;
}
if (ARCOpen(&arc, model_name, &model_info)) {
model = (tmdl_header*)ARCGetStartAddrInMem(&model_info);
ARCClose(&model_info);
} else {
OSReport("[T3D] CANNOT GET MODEL!!\n");
OSReport("ARCOpen could not get %s\n", model_name);
return false;
}
// bind it
if (model->version != 3 && model->version != 2) {
OSReport("[T3D] INVALID VERSION!!\n");
OSReport("this revision of T3D expects a v2 or v3 model file, not %d\n", model->version);
return false;
}
OSReport("Loading model version %d\n", model->version);
// fix up every shape's GX arrays
for (int shape_id = 0; shape_id < model->shape_count; shape_id++) {
u32 shape_offset = *(u32*)((u32)model + tmdl_header_sizes[model->version] + (4*shape_id));
tmdl_shape *shape = (tmdl_shape*)((u32)model + shape_offset);
void *pos_arr = (void*)((u32)model + shape->pos_arr_offset);
void *nrm_arr = (void*)((u32)model + shape->nrm_arr_offset);
void *uv_arr = (void*)((u32)model + shape->uv_arr_offset);
DCStoreRangeNoSync(pos_arr, shape->pos_arr_size);
DCStoreRangeNoSync(nrm_arr, shape->nrm_arr_size);
DCStoreRangeNoSync(uv_arr, shape->uv_arr_size);
}
if (model->version == 2) {
ARCFileInfo texture_info;
char texture_name[64];
snprintf(texture_name, 64, "t3d/tex_%s.tpl", mdlname);
if (ARCOpen(&arc, texture_name, &texture_info)) {
this->texture_res = (TPLPalette*)ARCGetStartAddrInMem(&texture_info);
ARCClose(&texture_info);
}
if (this->texture_res) {
TPLBind(this->texture_res);
}
}
if (model->version >= 3) {
// now fix up every material
tmdl_material *mat = (tmdl_material*)((u32)model + sizeof(tmdl_header) + (4*model->shape_count));
for (int mat_id = 0; mat_id < model->material_count; mat_id++) {
ARCFileInfo texture_info;
TPLPalette *texture = 0;
if (ARCOpen(&arc, mat->texture_name, &texture_info)) {
texture = (TPLPalette*)ARCGetStartAddrInMem(&texture_info);
ARCClose(&texture_info);
}
if (texture) {
TPLBind(texture);
TPLGetGXTexObjFromPalette(texture, &mat->texobj, 0);
GXInitTexObjWrapMode(&mat->texobj, GX_REPEAT, GX_REPEAT);
} else {
OSReport("[T3D] WARNING!! Texture %s was not found while loading model %s!\n", mat->texture_name, mdlname);
}
mat++;
}
}
// done!
this->model_res = model;
return true;
}
void Model::addToDrawList(Mtx mtx) {
if (RenderQueuePos >= OBJ_COUNT) {
OSReport("FATAL ERROR!!\n");
OSReport("T3D object limit reached, render queue will overflow\n");
return;
}
RenderInfo *info = &RenderQueue[RenderQueuePos++];
MTXCopy(mtx, info->matrix);
info->model = this;
}
void Model::draw(RenderInfo *info) {
Mtx matrix, inv_matrix;
MTXCopy(Camera.view_matrix, matrix);
MTXConcat(info->matrix, matrix, matrix);
GXLoadPosMtxImm(matrix, GX_PNMTX0);
MTXInverse(matrix, inv_matrix);
GXLoadNrmMtxImm(inv_matrix, GX_PNMTX0);
for (int i = 0; i < this->model_res->shape_count; i++)
this->drawShape(info, i);
}
void Model::drawShape(RenderInfo *info, int shape_id) {
u32 shape_offset = *(u32*)((u32)this->model_res + tmdl_header_sizes[this->model_res->version] + (4*shape_id));
tmdl_shape *shape = (tmdl_shape*)((u32)this->model_res + shape_offset);
if (this->model_res->version == 2) {
tmdl_materialv2 *materialv2 = (tmdl_materialv2*)((u32)this->model_res + shape->mat_offset);
this->setupMaterialGXv2(materialv2);
} else {
tmdl_material *material = (tmdl_material*)((u32)this->model_res + shape->mat_offset);
this->setupMaterialGX(material);
}
void *pos_arr = (void*)((u32)this->model_res + shape->pos_arr_offset);
void *nrm_arr = (void*)((u32)this->model_res + shape->nrm_arr_offset);
void *uv_arr = (void*)((u32)this->model_res + shape->uv_arr_offset);
GXSetArray(GX_VA_POS, pos_arr, 12);
GXSetArray(GX_VA_NRM, nrm_arr, 12);
GXSetArray(GX_VA_TEX0, uv_arr, 8);
void *dl_ptr = (void*)((u32)this->model_res + shape->dl_offset);
GXCallDisplayList(dl_ptr, shape->dl_size);
}
void Model::setupMaterialGXv2(tmdl_materialv2 *material) {
LastMaterial = 0; // reset this
if (material->texture_id != 0xFFFFFFFF) {
GXSetChanMatColor(GX_COLOR0A0, White);
GXSetChanMatColor(GX_COLOR1A1, White);
GXTexObj tex;
TPLGetGXTexObjFromPalette(this->texture_res, &tex, material->texture_id);
GXInitTexObjWrapMode(&tex, GX_REPEAT, GX_REPEAT);
GXLoadTexObj(&tex, GX_TEXMAP0);
GXSetNumTexGens(1);
GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
// TEV blending ops:
// First off, use the equivalent of GXSetTevOp(GX_TEVSTAGE0, GX_MODULATE)
//GXSetTevOp(GX_TEVSTAGE0, GX_MODULATE);
GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_TEXC, GX_CC_RASC, GX_CC_ZERO);
GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_RASA, GX_CA_ZERO);
GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
// Then do the same for stage1, but blend TEVPREV with RASC/RASA
GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_RASC, GX_CC_CPREV, GX_CC_ZERO);
GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_RASA, GX_CA_APREV, GX_CA_ZERO);
GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
} else {
GXSetChanMatColor(GX_COLOR0A0, material->mat_colour);
GXSetChanMatColor(GX_COLOR1A1, White);
GXSetNumTexGens(0);
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR1A1);
// TEV blending ops:
// First stage becomes GX_PASSCLR
GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
// Then blend this colour with RASA/RASC in the second stage
GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_RASC, GX_CC_CPREV, GX_CC_ZERO);
GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_RASA, GX_CA_APREV, GX_CA_ZERO);
GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
}
}
void Model::setupMaterialGX(tmdl_material *material) {
if (material == LastMaterial)
return;
LastMaterial = material; // small optimisation
if (material->texture_name[0] != 0) {
GXSetChanMatColor(GX_COLOR0A0, White);
GXSetChanMatColor(GX_COLOR1A1, White);
GXLoadTexObj(&material->texobj, GX_TEXMAP0);
GXSetNumTexGens(1);
GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR1A1);
// TEV blending ops:
// First off, use the equivalent of GXSetTevOp(GX_TEVSTAGE0, GX_MODULATE)
//GXSetTevOp(GX_TEVSTAGE0, GX_MODULATE);
GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_TEXC, GX_CC_RASC, GX_CC_ZERO);
GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_RASA, GX_CA_ZERO);
GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
// Then do the same for stage1, but blend TEVPREV with RASC/RASA
GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_RASC, GX_CC_CPREV, GX_CC_ZERO);
GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_RASA, GX_CA_APREV, GX_CA_ZERO);
GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
} else {
GXSetChanMatColor(GX_COLOR0A0, material->mat_colour);
GXSetChanMatColor(GX_COLOR1A1, White);
GXSetNumTexGens(0);
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR1A1);
// TEV blending ops:
// First stage becomes GX_PASSCLR
GXSetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
// Then blend this colour with RASA/RASC in the second stage
GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_RASC, GX_CC_CPREV, GX_CC_ZERO);
GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_RASA, GX_CA_APREV, GX_CA_ZERO);
GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
}
}
// todo: try out GXInit and see if it fixes the issues
// if so, it's something in there
void DrawQueue() {
LastMaterial = NULL;
GXInvalidateVtxCache();
GXInvalidateTexAll();
GXClearVtxDesc();
GXSetVtxDesc(GX_VA_POS, GX_INDEX16);
GXSetVtxDesc(GX_VA_NRM, GX_INDEX16);
GXSetVtxDesc(GX_VA_TEX0, GX_INDEX16);
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_NRM, GX_NRM_XYZ, GX_F32, 0);
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
GXSetCurrentMtx(GX_PNMTX0);
GXRenderModeObj *rm = Hook_GetGXRenderModeObj();
if (rm->field_rendering)
GXSetViewportJitter(0, 0, rm->fbWidth, rm->efbHeight, 0, 1, VIGetNextField());
else
GXSetViewport(0, 0, rm->fbWidth, rm->efbHeight, 0, 1);
GXSetProjection(Camera.projection_matrix, Camera.projection);
GXSetBlendMode(GX_BM_NONE, GX_BL_ONE, GX_BL_ONE, GX_LO_CLEAR);
GXSetCullMode(GX_CULL_FRONT);
GXSetZMode(GX_TRUE, GX_LEQUAL, GX_TRUE);
GXSetZCompLoc(GX_TRUE);
GXSetNumTevStages(2);
GXSetTevDirect(GX_TEVSTAGE0);
GXSetTevDirect(GX_TEVSTAGE1);
GXSetTevSwapModeTable(GX_TEV_SWAP0, GX_CH_RED, GX_CH_GREEN, GX_CH_BLUE, GX_CH_ALPHA);
GXSetTevSwapMode(GX_TEVSTAGE0, GX_TEV_SWAP0, GX_TEV_SWAP0);
GXSetTevSwapMode(GX_TEVSTAGE1, GX_TEV_SWAP0, GX_TEV_SWAP0);
/*GXInitLightDir(&light, 0, -1, 0);
GXInitLightSpot(&light, 45, GX_SP_COS);
GXInitLightDistAttn(&light, 30, 0.7, GX_DA_GENTLE);*/
GXLightObj light, light2;
Point3d lightPos = {0,-500.0,0};
MTXMultVec(Camera.view_matrix, &lightPos, &lightPos);
GXInitLightColor(&light, White);
GXInitLightPos(&light, lightPos.x, lightPos.y, lightPos.z);
GXLoadLightObjImm(&light, GX_LIGHT0);
GXInitLightColor(&light2, White);
GXInitSpecularDir(&light2, 0.5, 0.5, 0);
GXInitLightShininess(&light2, 4.0f);
GXLoadLightObjImm(&light2, GX_LIGHT1);
GXSetNumChans(2);
GXSetChanAmbColor(GX_COLOR0A0, (GXColor){128,128,128,255});
GXSetChanAmbColor(GX_COLOR1A1, (GXColor){128,128,128,255});
GXSetChanCtrl(GX_COLOR0A0, GX_ENABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHT0, GX_DF_CLAMP, GX_AF_NONE);
GXSetChanCtrl(GX_COLOR1A1, GX_ENABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHT1, GX_DF_CLAMP, GX_AF_SPEC);
GXSetFog(GX_FOG_NONE, 0, 0, 0, 0, (GXColor){0,0,0,0});
for (int idx = 0; idx < RenderQueuePos; idx++) {
RenderQueue[idx].model->draw(&RenderQueue[idx]);
}
RenderQueuePos = 0;
// THIS IS JUST FOR TESTING
static bool isCreated = false;
static mTexture_c *tex[14];
if (!isCreated) {
isCreated = true;
for (int i = 0; i < 14; i++) {
tex[i] = new mTexture_c(128, 8, GX_TF_RGBA8);
tex[i]->allocateBuffer();
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 128; x++) {
tex[i]->plotPixel(x, y, (GXColor){255,106,0,255});
}
}
//tex[i]->makeLinearGradient(i >> 1, 's', 0, 128, Black, White, ((i & 1) != 0));
tex[i]->makeLinearGradient(i >> 1, 's', 0, 128, (GXColor){255,106,0,255}, (GXColor){0,255,30,255}, false);
//tex[i]->plotPixel(0, 0, White);
//tex[i]->plotPixel(2, 2, White);
//tex[i]->plotPixel(4, 4, White);
tex[i]->flushDC();
}
}
Mtx matrix, inv_matrix;
MTXIdentity(matrix);
GXLoadPosMtxImm(matrix, GX_PNMTX0);
MTXInverse(matrix, inv_matrix);
GXLoadNrmMtxImm(inv_matrix, GX_PNMTX0);
GXSetChanMatColor(GX_COLOR0A0, White);
GXSetChanMatColor(GX_COLOR1A1, White);
GXSetNumTexGens(1);
GXSetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL);
GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0);
GXSetNumTevStages(1);
// TEV blending ops:
// First off, use the equivalent of GXSetTevOp(GX_TEVSTAGE0, GX_MODULATE)
GXSetTevOp(GX_TEVSTAGE0, GX_REPLACE);
/*GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_TEXC, GX_CC_RASC, GX_CC_ZERO);
GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_RASA, GX_CA_ZERO);
GXSetTevColorOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaOp(GX_TEVSTAGE0, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
// Then do the same for stage1, but blend TEVPREV with RASC/RASA
GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_RASC, GX_CC_CPREV, GX_CC_ZERO);
GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_RASA, GX_CA_APREV, GX_CA_ZERO);
GXSetTevColorOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);
GXSetTevAlphaOp(GX_TEVSTAGE1, GX_TEV_ADD, GX_TB_ZERO, GX_CS_SCALE_1, GX_TRUE, GX_TEVPREV);*/
GXCullMode(GX_CULL_NONE);
GXClearVtxDesc();
GXSetVtxDesc(GX_VA_POS, GX_DIRECT);
GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT);
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XYZ, GX_F32, 0);
GXSetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
float y = -40.0f;
for (int i = 0; i < 14; i++) {
tex[i]->load(GX_TEXMAP0);
GXBegin(GX_QUADS, GX_VTXFMT0, 4);
GXPosition3f32(-40.0f, y, -120.0f);
GXTexCoord2f32(0.0f, 1.0f);
GXPosition3f32(40.0f, y, -120.0f);
GXTexCoord2f32(1.0f, 1.0f);
GXPosition3f32(40.0f, y+5.0f, -120.0f);
GXTexCoord2f32(1.0f, 0.0f);
GXPosition3f32(-40.0f, y+5.0f, -120.0f);
GXTexCoord2f32(0.0f, 0.0f);
GXEnd();
y += 5.0f;
}
}
namespace Util {
/*void RotateToFace(const Vec &O, const Vec &P, const Vec &U, Mtx out) {
// http://forums.create.msdn.com/forums/p/10228/363692.aspx
Vec D, Right, Backwards, Up;
VECSubtract(&O, &P, &D);
VECCrossProduct(&U, &D, &Right);
VECNormalize(&Right, &Right);
VECCrossProduct(&Right, &U, &Backwards);
VECNormalize(&Backwards, &Backwards);
VECCrossProduct(&Backwards, &Right, &Up);
out[0][0] = Right.x;
out[0][1] = Right.y;
out[0][2] = Right.z;
out[0][3] = 0;
out[1][0] = Up.x;
out[1][1] = Up.y;
out[1][2] = Up.z;
out[1][3] = 0;
out[2][0] = Backwards.x;
out[2][1] = Backwards.y;
out[2][2] = Backwards.z;
out[2][3] = 0;
}*/
};
};
|