comparison ps2util.cc @ 99:c534f339ee8b

change c++
author e085768
date Thu, 02 Jun 2011 17:51:41 +0900
parents ps2util.c@1033fece71ce
children e5f2eb98b575
comparison
equal deleted inserted replaced
98:1033fece71ce 99:c534f339ee8b
1 /* ps2util.c */
2
3 #include <string.h>
4 #include <stdio.h>
5 #include <stdlib.h>
6 #include <math.h>
7 #include "libps2.h"
8 #include "ps2util.h"
9
10 /*
11 たぶん、本当は読み込んだ xml file から情報を取得するとかそんなんだと思う
12 どんな処理か分からないので、とりあえず、初期化している。
13 */
14
15 OBJECT *ps2util_obj_Create_fromXML(char *filename)
16 {
17 OBJECT *body;
18
19 /*
20 body->xyz = {0,0,0,0};
21 body->angle = {0,0,0,0};
22 body->transfer = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
23 body->*name = filename;
24 body->*free_me = NULL;
25 */
26
27 return body;
28 }
29
30
31
32 void ps2util_obj_Set_effect(OBJECT *body, int def)
33 {
34 //none
35 }
36
37 // ベクトル v1 をベクトル v2 にコピーする
38 void ps2_vu0_copy_vector(FVECTOR directionA, FVECTOR directionB)
39 {
40 memcpy(directionA, directionB, sizeof(FVECTOR));
41 }
42
43
44 void ps2util_obj_Renew_transMatrix(OBJECT *car){
45 //none
46 }
47
48
49 /*
50 ps2 内の texture.c から
51 */
52 TEXTURE* read_png_file(char *texname)
53 {
54 printf("trace\n");
55 //とりあえず戻り値を返してエラーをどうにか
56 TEXTURE* tex;
57
58 return tex;
59 }
60
61
62
63 int ps2util_tex_Set(TEXTURE* tex)
64 {
65 return -1;
66 }
67
68 int ps2util_sprite_Create(ps2utilSprite *Sp, TEXTURE *sprite_tex)
69 {
70 return -1;
71 }
72
73
74 void ps2util_obj_Set_texture(OBJECT* car_body, TEXTURE *tex)
75 {
76 //none
77 }
78
79 // 与えられた行列を単位行列に変換する
80 void ps2_vu0_unit_matrix(FMATRIX m)
81 {
82 m[0][1] = m[0][2] = m[0][3] = 0;
83 m[1][0] = m[1][2] = m[1][3] = 0;
84 m[2][0] = m[2][1] = m[2][3] = 0;
85 m[3][0] = m[3][1] = m[3][2] = 0;
86 m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
87 }
88
89 /*
90 Y軸を中心とした行列の回転
91 回転角 rx より X 軸を中心とした回転マトリックスを求めて、マトリックス m1 に左側から乗算して、その結果をマトリックス m0 に与える。
92 X 軸だけでなく Y 軸、Z 軸を中心とした関数もある。また3ついっんに回転させる関数もある。
93 */
94 void ps2_vu0_rot_matrix_y(FMATRIX result, FMATRIX m, float radian)
95 {
96 // 回転行列を作ってかけてやれば良い
97
98 m[0][1] = m[0][2] = m[0][3] = 0;
99 m[1][0] = m[1][2] = m[1][3] = 0;
100 m[2][0] = m[2][1] = m[2][3] = 0;
101 m[3][0] = m[3][1] = m[3][2] = 0;
102 m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
103
104
105 m[0][0] = sinf(radian);
106 m[2][2] = sinf(radian);
107 m[0][2] = -cosf(radian);
108 m[2][0] = cosf(radian);
109
110 FMATRIX m1;// = m;
111 memcpy(&m1, m, sizeof(FMATRIX));
112
113 ps2_vu0_mul_matrix(result, m1, m);
114 }
115
116 // ベクトルの計算
117 // マトリックス m にベクトル を右から乗算して result に与える
118 void ps2_vu0_apply_matrix(FVECTOR result, FMATRIX m, FVECTOR v)
119 {
120 result[0] = m[0][0] * v[0] + m[0][1] * v[1] + m[0][2] * v[2] + m[0][3] * v[3] ;
121 result[1] = m[1][0] * v[0] + m[1][1] * v[1] + m[1][2] * v[2] + m[1][3] * v[3] ;
122 result[2] = m[2][0] * v[0] + m[2][1] * v[1] + m[2][2] * v[2] + m[2][3] * v[3] ;
123 result[3] = m[3][0] * v[0] + m[3][1] * v[1] + m[3][2] * v[2] + m[3][3] * v[3] ;
124 }
125
126
127 void ps2_vu0_scale_vector(FVECTOR mov, FVECTOR car_direction, float car_speed)
128 {
129 mov[0] = car_direction[0] * car_speed ;
130 mov[1] = car_direction[1] * car_speed ;
131 mov[2] = car_direction[2] * car_speed ;
132 mov[3] = car_direction[3];
133 }
134
135 // ベクトル v1 の各要素とベクトル v2 の各要素を各々加算してv0に与える
136 // v0 = v1+v2
137 void ps2_vu0_add_vector(FVECTOR result, FVECTOR v0, FVECTOR v1)
138 {
139 result[0] = v0[0] + v1[0];
140 result[1] = v0[1] + v1[1];
141 result[2] = v0[2] + v1[2];
142 // result[3] = v0[3] + v1[3];
143 result[3] = v0[3];
144 }
145
146 // 外積
147 void ps2_vu0_outer_product(FVECTOR result, FVECTOR v0, FVECTOR v1)
148 {
149 result[0] = v0[1] * v1[2] - v0[2] * v1[1] ;
150 result[1] = v0[0] * v1[2] - v0[2] * v1[0] ;
151 result[2] = v0[0] * v1[1] - v0[1] * v1[0] ;
152 result[3] = 1;
153 }
154
155 // 内積
156 float ps2_vu0_inner_product(FVECTOR v0, FVECTOR v1)
157 {
158 return v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];
159 }
160
161
162 void ps2_vu0_mul_matrix(FMATRIX result, FMATRIX m0, FMATRIX m1)
163 {
164 result[0][0] = m0[0][0] * m1[0][0] + m0[0][1] * m1[1][0] + m0[0][2] * m1[2][0] + m0[0][3] * m1[3][0];
165 result[0][1] = m0[0][0] * m1[0][1] + m0[0][1] * m1[1][1] + m0[0][2] * m1[2][1] + m0[0][3] * m1[3][1];
166 result[0][2] = m0[0][0] * m1[0][2] + m0[0][1] * m1[1][2] + m0[0][2] * m1[2][2] + m0[0][3] * m1[3][2];
167 result[0][3] = m0[0][0] * m1[0][3] + m0[0][1] * m1[1][3] + m0[0][2] * m1[2][3] + m0[0][3] * m1[3][3];
168
169 result[1][0] = m0[1][0] * m1[0][0] + m0[1][1] * m1[1][0] + m0[1][2] * m1[2][0] + m0[1][3] * m1[3][0];
170 result[1][1] = m0[1][0] * m1[0][1] + m0[1][1] * m1[1][1] + m0[1][2] * m1[2][1] + m0[1][3] * m1[3][1];
171 result[1][2] = m0[1][0] * m1[0][2] + m0[1][1] * m1[1][2] + m0[1][2] * m1[2][2] + m0[1][3] * m1[3][2];
172 result[1][3] = m0[1][0] * m1[0][3] + m0[1][1] * m1[1][3] + m0[1][2] * m1[2][3] + m0[1][3] * m1[3][3];
173
174 result[2][0] = m0[2][0] * m1[0][0] + m0[2][1] * m1[1][0] + m0[2][2] * m1[2][0] + m0[2][3] * m1[3][0];
175 result[2][1] = m0[2][0] * m1[0][1] + m0[2][1] * m1[1][1] + m0[2][2] * m1[2][1] + m0[2][3] * m1[3][1];
176 result[2][2] = m0[2][0] * m1[0][2] + m0[2][1] * m1[1][2] + m0[2][2] * m1[2][2] + m0[2][3] * m1[3][2];
177 result[2][3] = m0[2][0] * m1[0][3] + m0[2][1] * m1[1][3] + m0[2][2] * m1[2][3] + m0[2][3] * m1[3][3];
178
179 result[3][0] = m0[3][0] * m1[0][0] + m0[3][1] * m1[1][0] + m0[3][2] * m1[2][0] + m0[3][3] * m1[3][0];
180 result[3][1] = m0[3][0] * m1[0][1] + m0[3][1] * m1[1][1] + m0[3][2] * m1[2][1] + m0[3][3] * m1[3][1];
181 result[3][2] = m0[3][0] * m1[0][2] + m0[3][1] * m1[1][2] + m0[3][2] * m1[2][2] + m0[3][3] * m1[3][2];
182 result[3][3] = m0[3][0] * m1[0][3] + m0[3][1] * m1[1][3] + m0[3][2] * m1[2][3] + m0[3][3] * m1[3][3];
183 }
184
185
186 void ps2_vu0_copy_matrix(FMATRIX transfer, FMATRIX pose)
187 {
188 memcpy(transfer, pose, sizeof(FMATRIX));
189 }
190
191 void ps2util_obj_Free(OBJECT* obj)
192 {
193 free(obj);
194 }
195
196
197
198 void ps2_vu0_sub_vector(FVECTOR result, FVECTOR v0, FVECTOR v1)
199 {
200 result[0] = v0[0] - v1[0];
201 result[1] = v0[1] - v1[1];
202 result[2] = v0[2] - v1[2];
203 result[3] = v0[3];// - v1[3];
204 }
205
206
207
208 void ps2_vu0_normalize(FVECTOR result, FVECTOR v)
209 {
210 // 大きさで割ってるだけって
211 float d = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
212 result[0] = v[0] / d;
213 result[1] = v[1] / d;
214 result[2] = v[2] / d;
215 result[3] = 1;
216 }
217
218
219 void xml_free(PolygonInfo xml)
220 {
221 //none
222 }
223
224
225 void ps2util_obj_Draw(OBJECT *object)
226 {
227 //none
228 }
229
230
231 void ps2util_sprite_Destroy(ps2utilSprite *title_sprite )
232 {
233 //none
234 }
235
236
237
238
239 void ps2util_sprite_Set_basicAttribute(ps2utilSprite *p,
240 unsigned short x, unsigned short y,
241 unsigned short sptable_tw1, unsigned short sptable_th1,
242 unsigned short sptable_tx, unsigned short sptable_ty,
243 unsigned short sptable_tw2, unsigned short sptable_th2,
244 int sprite_prio_foreground)
245 {
246 //none
247 }
248
249 void ps2util_sprite_Request(ps2utilSprite *p)
250 {
251 //none
252 }
253
254
255 void ps2util_sprite_Unuse_alpha(ps2utilSprite *sp)
256 {
257 //none
258 }
259
260 void ps2util_graphic_Init()
261 {
262 //none
263 }
264
265
266 /*
267 ps2 依存関係の sprite.c より引用。
268 */
269 #define SPRITE_HAS_4VERTEXIS 4
270
271 #define PS2_GS_XYZ3 1 // なにかわからん定数だから適当に作りました
272
273 void
274 sprite_disappear( SPRITE* sprite )
275 {
276 int i;
277 GsSpritePacket* packet = sprite->gs_packet;
278 for (i=0; i<SPRITE_HAS_4VERTEXIS; i++)
279 packet->primData[i].xyz_addr = PS2_GS_XYZ3;
280 }
281
282
283
284
285 /*
286 からの関数
287 ps2 依存関係にあったけど、( name_dictionary.c ) の中のもの
288 だけど、他にも持ってくるものが増えるので、とりあえず、からの関数に
289 */
290 void delete_name_dictionary(const char *string)
291 {
292 /*
293 int number;
294 NAME_DIC *dic_ptr;
295
296 if (string == NULL) return;
297
298 number = hash_func(string,NAME_HASH_SIZE);
299
300 for (dic_ptr=name_hash+number;dic_ptr->name;dic_ptr=name_hash+number) {
301 if (!strcmp(string,dic_ptr->name)) {
302 dic_ptr->ref_num--;
303 if (dic_ptr->ref_num == 0) {
304 free(dic_ptr->name);
305 dic_ptr->name = NULL;
306 }
307 return;
308 } else {
309 number += REHASH_NUM;
310 if (number > NAME_HASH_SIZE) number -= NAME_HASH_SIZE;
311 }
312 }
313 */
314 }
315
316
317
318 /*
319 ps2 依存関係から持ってきた。
320 テクスチャに割り振ったメモリの解放処理?
321 元ファイル:texture.c
322 */
323 void free_texture(TEXTURE *tex)
324 {
325 if (tex == NULL) return;
326
327 delete_name_dictionary(tex->name);
328 free(tex->free_texenv);
329 free(tex->free_image);
330 free(tex);
331 }
332
333
334 /*
335 ps2 依存関係内の、texture.c から拝借
336 この malloc によるメモリ取得をあちこちで行っているっぽい
337 cerium にある。
338 */
339 int malloc_align16(void *free, void *aligned, int size)
340 {
341 char *index;
342 unsigned int *f=(unsigned int *)free,*a=(unsigned int *)aligned;
343
344 if (free == NULL || aligned == NULL || size <= 0) return(-1);
345
346 index = (char *)malloc(size + ALIGN_16BYTE);
347 if (index == NULL) {
348 return(-1);
349 }
350
351 *f = *a = (unsigned long int)index;
352 if (((unsigned long int)index % ALIGN_16BYTE) != 0) {
353 index += ALIGN_16BYTE - ((unsigned long int)index % ALIGN_16BYTE);
354 *a = (unsigned long int)index;
355 }
356
357 return(0);
358 }
359
360
361
362 // miya
363 void ps2util_tex_Exclude( TEXTURE* t )
364 {
365 char *miyahira;
366 miyahira = "なにこの関数?";
367 }
368
369 void ps2util_sprite_Draw()
370 {
371 printf("ps2util_sprite_Draw()\n");
372 }
373
374 void ps2util_graphic_Finish()
375 {
376 printf("ps2util_graphic_Finish()\n");
377 }
378
379
380 // title.cに書いてた
381 void ps2util_sprite_Use_alpha( ps2utilSprite *title )
382 {
383 printf("ps2util_sprite_Use_alpha()\n");
384 }