graphic_00.c
3.41 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
/*============================================================================
NINTENDO64 TECHNICAL SUPPORT CENTER
NINTENDO64 SAMPLE PROGRAM 1
Copyright (C) 1997, NINTENDO Co,Ltd.
============================================================================*/
#include <ultra64.h>
#include <PR/ramrom.h>
#include <assert.h>
#include "def.h"
#include "vram.h"
#include "segment.h"
#include "message.h"
#include "nnsched.h"
#include "graphic.h"
#include "controller.h"
extern Gfx cont_finish_dl[];
void ModelController(Dynamic*,ModelMtx *);
extern ModelMtx mtx_cont[];
/*-----------------------------------------------------------------------------
graphic00
-----------------------------------------------------------------------------*/
void graphic_00(void)
{
Dynamic* dynamic_ptr;
NNScTask *t;
static LookAt lookat;
u16 perspNorm;
u32 cnt;
/*
ディスプレイリストバッファ・タスクバッファの指定
*/
dynamic_ptr = &gfx_dynamic[gfx_gtask_no];
glist_ptr = &gfx_glist[gfx_gtask_no][0];
t = &gfx_task[gfx_gtask_no];
/* RSPとRDPの設定 */
gfxRCPInit();
/* フレームバッファとZバッファのクリア */
gfxClearCfb();
/* 投影マトリックスの計算と設定 */
guPerspective(&dynamic_ptr->projection, &perspNorm,
33, 320.0/240.0, 10, 2000, 1.0);
guLookAtReflect(&dynamic_ptr->viewing, &lookat,
0, 50, -600 ,
0, 0, 0,
0, 1, 0);
gSPPerspNormalize(glist_ptr++, perspNorm);
gSPLookAt(glist_ptr++, &lookat);
gSPMatrix(glist_ptr++, &(dynamic_ptr->projection),
G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH);
gSPMatrix(glist_ptr++, &(dynamic_ptr->viewing),
G_MTX_PROJECTION | G_MTX_MUL | G_MTX_NOPUSH);
/* モデルの描画 */
for(cnt = 0; cnt < numControllers; cnt++){
ModelController(dynamic_ptr,&mtx_cont[cnt]);
}
/* end top-level display list */
gDPFullSync(glist_ptr++);
gSPEndDisplayList(glist_ptr++);
/* Flush the dynamic segmnet */
osWritebackDCacheAll();
gfxTaskStart(t, gfx_glist[gfx_gtask_no],
(s32)(glist_ptr - gfx_glist[gfx_gtask_no]) * sizeof (Gfx),
GFX_GSPCODE_F3DEX2, NN_SC_SWAPBUFFER);
}
/*-----------------------------------------------------------------------------
コントローラのモデル表示
-----------------------------------------------------------------------------*/
void ModelController(Dynamic* dynamic_ptr,ModelMtx *model_mtx)
{
Mtx rotate_x;
Mtx rotate_y;
Mtx rotate_z;
/* モデル座標系の計算 */
guTranslate(&(model_mtx->trans), model_mtx->pos_x, model_mtx->pos_y, model_mtx->pos_z);
guScale(&(model_mtx->scale), model_mtx->size, model_mtx->size, model_mtx->size);
guRotate(&rotate_x, model_mtx->rot_x, 1.0, 0.0, 0.0);
guRotate(&rotate_y, model_mtx->rot_y, 0.0, 1.0, 0.0);
guRotate(&rotate_z, model_mtx->rot_z, 0.0, 0.0, 1.0);
guMtxCatL(&rotate_x,&rotate_y, &model_mtx->rotate);
guMtxCatL(&rotate_z,&model_mtx->rotate,&model_mtx->rotate);
/* モデルマトリックスの設定 */
gSPMatrix(glist_ptr++, &(model_mtx->trans),
G_MTX_MODELVIEW | G_MTX_LOAD | G_MTX_NOPUSH);
gSPMatrix(glist_ptr++, &(model_mtx->rotate),
G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
gSPMatrix(glist_ptr++, &(model_mtx->scale),
G_MTX_MODELVIEW | G_MTX_MUL | G_MTX_NOPUSH);
gSPSegment(glist_ptr++, STATIC_SEGMENT, osVirtualToPhysical(gfx_dlist_buf[0]));
/* モデルのディスプレイリスト */
gSPDisplayList(glist_ptr++, cont_finish_dl);
}