115
|
1 //SgoexCerium.ccより
|
|
2 #include "matrix_calc.h"
|
|
3 #include "TaskManager.h"
|
|
4 #include "SceneGraph.h"
|
|
5 #include "Application.h"
|
|
6
|
|
7 #include <stdio.h>
|
|
8 #include <stdlib.h>
|
|
9 #include "libps2.h"
|
|
10 #include "ps2util.h"
|
|
11 #include <stdbool.h>
|
|
12
|
|
13 #define DEFOBJ 100
|
|
14 #define SPRITE_COL 0x4f
|
|
15 #define SCREEN_HALF_W 320
|
|
16 #define SCREEN_HALF_H 240
|
|
17
|
|
18 static SpriteTable sptable[DEFOBJ];
|
|
19 static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック
|
|
20 static unsigned int sp_counter;
|
|
21 static bool flag_spriteInited = false; // スプライトロードフラグ
|
|
22
|
|
23 static TEXTURE *sprite_tex;
|
|
24
|
|
25
|
|
26
|
|
27 extern Viewer *droot;
|
95
|
28
|
115
|
29 static SceneGraphPtr root;
|
|
30
|
|
31
|
|
32 //SgoexCerium.ccより
|
|
33 void
|
|
34 flip()
|
|
35 {
|
|
36 CameraPtr camera = droot->sgroot->getCamera();
|
|
37
|
|
38 droot->sgroot->flip();
|
|
39 droot->sgroot->lightCalc();
|
|
40
|
|
41 root = droot->createSceneGraph();
|
|
42 //root->xyz[0] = screen_w/2;
|
|
43 //root->xyz[1] = screen_h/2;;
|
|
44 root->xyz[0] = 0;
|
|
45 root->xyz[1] = 0;
|
|
46 root->xyz[2] = 30.0f;
|
|
47
|
|
48 /*親の回転、座標から、子の回転、座標を算出*/
|
|
49 get_matrix(root->matrix, root->angle, root->xyz, camera->matrix);
|
|
50 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
|
|
51 get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix);
|
|
52 //出力して、次のものを出力するための準備
|
|
53 droot->setSceneData(root);
|
|
54 }
|
|
55
|
|
56
|
|
57
|
|
58
|
95
|
59
|
115
|
60 /*void
|
|
61 gSprite_DefSprite(int number, int tx, int ty, int tw, int th)
|
|
62 {
|
|
63 sptable[number].tx = tx;
|
|
64 sptable[number].ty = ty;
|
|
65 sptable[number].tw = tw;
|
|
66 sptable[number].th = th;
|
|
67 }*/
|
|
68 void
|
|
69 gSprite_DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj)
|
|
70 {
|
|
71 SpriteTable *m = &sptable[number];
|
|
72 m->w = w;
|
|
73 m->h = h;
|
|
74 m->color = (color & 32);
|
|
75 m->mx = w / 2; //画像の中心を座標としたいらしい。
|
|
76 m->my = h / 2;
|
|
77 m->tex_w = power_of_two(m->w);
|
|
78 m->tex_h = power_of_two(m->h);
|
|
79 m->texture = (int *)name;
|
|
80
|
|
81 }
|
|
82
|
|
83
|
|
84
|
|
85
|
|
86
|
|
87 /*void
|
|
88 gSprite_PutSprite(int number, int x, int y)
|
|
89 {
|
|
90 ps2utilSprite *p = &sp[sp_counter];
|
|
91
|
|
92 ps2util_sprite_Set_basicAttribute(
|
|
93 p,
|
|
94 (unsigned short)x, (unsigned short)y,
|
|
95 (unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2,
|
|
96 (unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
|
|
97 (unsigned short)sptable[number].tw, (unsigned short)sptable[number].th,
|
|
98 SPRITE_PRIO_FOREGROUND);
|
|
99
|
|
100 ps2util_sprite_Request(p);
|
|
101 sp_counter++;
|
|
102 }*/
|
|
103 void
|
|
104 gSprite_PutSprite(int number, short x, short y, int zorder)
|
|
105 {
|
|
106 SpriteTable *m = &sptable[number];
|
|
107 char *name = (char *) m->texture;
|
|
108 if (!name) {
|
|
109 printf("PutSprite %d unknown\n",number);
|
|
110 return;
|
|
111 }
|
|
112 SceneGraphPtr object = droot->createSceneGraph(name);
|
|
113 //object->c_xyz[0] = m->mx;
|
|
114 //object->c_xyz[1] = m->my;
|
|
115 root->addChild(object);
|
|
116
|
|
117 object->xyz[0] -= object->c_xyz[0]*my_scale;
|
|
118 object->xyz[1] -= object->c_xyz[1]*my_scale;
|
|
119 object->xyz[2] -= object->c_xyz[2];
|
|
120
|
|
121 object->xyz[0] += x+m->mx;
|
|
122 object->xyz[1] += y+m->my;
|
|
123 object->xyz[2] += zorder * 0.01;
|
|
124
|
|
125 float scale[] = {my_scale,my_scale,1};
|
|
126 //float c_xyz[] = {0,0,0};
|
|
127 //scale_matrix(object->matrix, scale, c_xyz);
|
|
128
|
|
129 /*親の回転、座標から、子の回転、座標を算出*/
|
|
130 //get_matrix_scale(object->matrix, object->angle, object->xyz, scale, root->matrix);
|
|
131
|
|
132 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
|
|
133 // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix);
|
|
134 }
|
|
135
|
|
136
|
|
137
|
|
138
|
0
|
139
|
95
|
140
|
115
|
141 /*void
|
|
142 gSprite_PutSpriteEx(int number, int x, int y, float w, float h)
|
|
143 {
|
|
144 ps2utilSprite *p = &sp[sp_counter];
|
|
145
|
|
146 ps2util_sprite_Set_basicAttribute(
|
|
147 p,
|
|
148 (unsigned short)x, (unsigned short)y,
|
|
149 (unsigned short)sptable[number].tw*w, (unsigned short)sptable[number].th*h,
|
|
150 (unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
|
|
151 (unsigned short)sptable[number].tw, (unsigned short)sptable[number].th,
|
|
152 SPRITE_PRIO_FOREGROUND);
|
|
153
|
|
154 ps2util_sprite_Request(p);
|
|
155 sp_counter++;
|
|
156 }*/
|
|
157 void
|
|
158 PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle)
|
|
159 {
|
|
160 if (1) {
|
|
161 PutSprite(1, x, y, number);
|
|
162 return;
|
|
163 }
|
|
164
|
|
165 SpriteTable *m = &sptable[number];
|
|
166 char *name = (char *) m->texture;
|
|
167 if (!name) {
|
|
168 printf("PutSpriteEx %d unknown\n",number);
|
|
169 return;
|
|
170 }
|
|
171 SceneGraphPtr object = droot->createSceneGraph(name);
|
|
172 root->addChild(object);
|
|
173
|
|
174 float scale[] = {my_scale*scalex*4,my_scale*scaley*4,1};
|
|
175
|
|
176 /*親の回転、座標から、子の回転、座標を算出*/
|
|
177 object->xyz[0] = x - object->c_xyz[0] * my_scale - m->w*my_scale;
|
|
178 object->xyz[1] = y - object->c_xyz[1] * my_scale - m->h*my_scale;
|
|
179 object->xyz[2] = number * 0.01;
|
|
180 //object->c_xyz[0] = m->mx;
|
|
181 //object->c_xyz[1] = m->my;
|
|
182 object->angle[3] = angle * (3.1415926*2/4096);
|
|
183 get_matrix(object->matrix, object->angle, object->xyz, root->matrix);
|
|
184 float c_xyz[] = {0,0,0};
|
|
185 scale_matrix(object->matrix, scale, c_xyz);
|
|
186 /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
|
|
187 // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix);
|
|
188 }
|
|
189
|
|
190
|
|
191
|
|
192
|
|
193
|
|
194
|
|
195
|
|
196 //ここいらはどうやら、スプライトを取得する部分。
|
|
197
|
|
198 static void
|
|
199 gSprite_Init_Png(const char *texname)
|
|
200 {
|
|
201 if (!(sprite_tex = read_png_file(texname))) {
|
|
202 fprintf(stderr,
|
|
203 "cannot creat texture - init_png().\n");
|
|
204 fflush(stderr);
|
|
205 exit(EXIT_FAILURE);
|
|
206 }
|
|
207
|
|
208 if (ps2util_tex_Set(sprite_tex) == -1) {
|
|
209 fprintf(stderr,
|
|
210 "cannot set texture - init_png().\n");
|
|
211 fflush(stderr);
|
|
212 exit(EXIT_FAILURE);
|
|
213 }
|
95
|
214
|
115
|
215 }
|
|
216
|
|
217 static void
|
|
218 gSprite_Create()
|
|
219 {
|
|
220 int i;
|
|
221
|
|
222 for (i=0; i<DEFOBJ; i++) {
|
|
223 if (ps2util_sprite_Create(&sp[i], sprite_tex) == -1) {
|
|
224 fprintf(stderr,
|
|
225 "cannot create sprite No.%d - create_sprite()\n", i);
|
|
226 fflush(stderr);
|
|
227 exit(EXIT_FAILURE);
|
|
228 }
|
|
229 ps2util_sprite_Unuse_alpha(&sp[i]);
|
|
230 }
|
|
231
|
|
232 flag_spriteInited = false;
|
|
233 }
|
|
234
|
|
235
|
|
236 void
|
|
237 gSprite_Init()
|
|
238 {
|
|
239 ps2util_graphic_Init();
|
|
240 //gSprite_Init_Png("img/main2.png");
|
|
241 //gSprite_Create(); // スプライト生成
|
|
242
|
|
243 sgroot->createFromXMLfile("./xml_files/boss.xml");
|
|
244
|
|
245 /* gSprite_DefSprite(10, 1, 1, 512, 666); // タイトル
|
|
246 gSprite_DefSprite(17, 1, 35, 33, 33); // 選択マーク
|
|
247 gSprite_DefSprite(23, 1, 1, 106, 34); // スピードメーター
|
|
248 gSprite_DefSprite(24, 51, 40, 18, 20); // 右矢印
|
|
249 gSprite_DefSprite(25, 33, 40, 17, 20); // 左矢印
|
|
250 gSprite_DefSprite(26, 56, 89, 55, 26); // km/h
|
|
251 gSprite_DefSprite(27, 62, 62, 39, 26); // Rap
|
|
252 gSprite_DefSprite(28, 430, 62, 53, 46); // 1p
|
|
253 gSprite_DefSprite(29, 460, 6, 53, 46); // 2P
|
|
254 gSprite_DefSprite(51, 333, 116, 165, 140); // 選択画面の車
|
|
255 gSprite_DefSprite(52, 181, 116, 165, 140);
|
|
256 gSprite_DefSprite(53, 12, 116, 165, 140);
|
|
257 gSprite_DefSprite(81, 115, 1, 148, 114); // 選択画面のコース
|
|
258 // 本当は (82, 272,...)です。二つ目のコース絵がないので
|
|
259 gSprite_DefSprite(82, 272, 1, 148, 114);*/
|
|
260
|
|
261 }
|
|
262
|
|
263
|
|
264 static void
|
|
265 gSprite_Clear()
|
|
266 {
|
|
267 int i;
|
|
268
|
|
269 for (i=0; i<DEFOBJ; i++) {
|
|
270 sprite_disappear(&sp[i].attribute);
|
|
271 }
|
|
272 sp_counter = 0;
|
|
273 }
|
|
274
|
|
275
|
|
276
|
|
277 void
|
|
278 gSprite_Draw_Reset()
|
|
279 {
|
|
280 if (flag_spriteInited == true) {
|
|
281 gSprite_Clear();
|
|
282 }
|
|
283 }
|
|
284
|
|
285
|
|
286
|
|
287 void
|
|
288 gSprite_PutSprite_Pause()
|
|
289 {
|
|
290 }
|