diff ps2util.cc @ 99:c534f339ee8b

change c++
author e085768
date Thu, 02 Jun 2011 17:51:41 +0900
parents ps2util.c@1033fece71ce
children e5f2eb98b575
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/ps2util.cc	Thu Jun 02 17:51:41 2011 +0900
@@ -0,0 +1,384 @@
+/* ps2util.c */
+
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h> 
+#include "libps2.h"
+#include "ps2util.h"
+
+/*
+  たぶん、本当は読み込んだ xml file から情報を取得するとかそんなんだと思う
+  どんな処理か分からないので、とりあえず、初期化している。
+*/
+
+OBJECT *ps2util_obj_Create_fromXML(char *filename)
+{
+  OBJECT *body;
+
+  /*
+  body->xyz = {0,0,0,0};
+  body->angle = {0,0,0,0};
+  body->transfer = { {0,0,0,0}, {0,0,0,0}, {0,0,0,0}, {0,0,0,0} };
+  body->*name = filename;
+  body->*free_me = NULL;
+  */
+  
+  return body;
+}
+
+
+
+void ps2util_obj_Set_effect(OBJECT *body, int def)
+{
+  //none
+}
+
+// ベクトル v1 をベクトル v2 にコピーする
+void ps2_vu0_copy_vector(FVECTOR directionA, FVECTOR directionB)
+{
+  memcpy(directionA, directionB, sizeof(FVECTOR));
+}
+
+
+void ps2util_obj_Renew_transMatrix(OBJECT *car){
+  //none
+}
+
+
+/*
+  ps2 内の texture.c から
+*/
+TEXTURE* read_png_file(char *texname)
+{
+  printf("trace\n");  
+  //とりあえず戻り値を返してエラーをどうにか
+  TEXTURE* tex;
+  
+  return tex;
+}
+
+
+
+int ps2util_tex_Set(TEXTURE* tex)
+{
+  return -1;
+}
+
+int ps2util_sprite_Create(ps2utilSprite *Sp, TEXTURE *sprite_tex)
+{
+  return -1;
+}
+
+
+void ps2util_obj_Set_texture(OBJECT* car_body, TEXTURE *tex)
+{
+  //none
+}
+
+// 与えられた行列を単位行列に変換する
+void ps2_vu0_unit_matrix(FMATRIX m)
+{
+  m[0][1] = m[0][2] = m[0][3] = 0;
+  m[1][0] = m[1][2] = m[1][3] = 0;
+  m[2][0] = m[2][1] = m[2][3] = 0;
+  m[3][0] = m[3][1] = m[3][2] = 0;
+  m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
+}
+
+/*
+Y軸を中心とした行列の回転 
+回転角 rx より X 軸を中心とした回転マトリックスを求めて、マトリックス m1 に左側から乗算して、その結果をマトリックス m0 に与える。 
+X 軸だけでなく Y 軸、Z 軸を中心とした関数もある。また3ついっんに回転させる関数もある。
+*/
+void ps2_vu0_rot_matrix_y(FMATRIX result, FMATRIX m, float radian)
+{
+  // 回転行列を作ってかけてやれば良い
+
+  m[0][1] = m[0][2] = m[0][3] = 0;
+  m[1][0] = m[1][2] = m[1][3] = 0;
+  m[2][0] = m[2][1] = m[2][3] = 0;
+  m[3][0] = m[3][1] = m[3][2] = 0;
+  m[0][0] = m[1][1] = m[2][2] = m[3][3] = 1.0;
+
+  
+  m[0][0] = sinf(radian);
+  m[2][2] = sinf(radian);
+  m[0][2] = -cosf(radian);
+  m[2][0] = cosf(radian);
+  
+  FMATRIX m1;// = m;
+  memcpy(&m1, m, sizeof(FMATRIX));
+
+  ps2_vu0_mul_matrix(result, m1, m);
+}
+
+// ベクトルの計算
+// マトリックス m にベクトル  を右から乗算して result に与える
+void ps2_vu0_apply_matrix(FVECTOR result, FMATRIX m, FVECTOR v)
+{
+  result[0] = m[0][0] * v[0] + m[0][1] * v[1] + m[0][2] * v[2] + m[0][3] * v[3] ;
+  result[1] = m[1][0] * v[0] + m[1][1] * v[1] + m[1][2] * v[2] + m[1][3] * v[3] ;
+  result[2] = m[2][0] * v[0] + m[2][1] * v[1] + m[2][2] * v[2] + m[2][3] * v[3] ;
+  result[3] = m[3][0] * v[0] + m[3][1] * v[1] + m[3][2] * v[2] + m[3][3] * v[3] ;
+}
+
+
+void ps2_vu0_scale_vector(FVECTOR mov, FVECTOR car_direction, float car_speed)
+{
+  mov[0] = car_direction[0] * car_speed ;
+  mov[1] = car_direction[1] * car_speed ;
+  mov[2] = car_direction[2] * car_speed ;
+  mov[3] = car_direction[3];
+}
+
+// ベクトル v1 の各要素とベクトル v2 の各要素を各々加算してv0に与える
+// v0 = v1+v2
+void ps2_vu0_add_vector(FVECTOR result, FVECTOR v0, FVECTOR v1)
+{
+  result[0] = v0[0] + v1[0];
+  result[1] = v0[1] + v1[1];
+  result[2] = v0[2] + v1[2];
+  //  result[3] = v0[3] + v1[3];
+  result[3] = v0[3];
+}
+
+// 外積
+void ps2_vu0_outer_product(FVECTOR result, FVECTOR v0, FVECTOR v1)
+{
+  result[0] = v0[1] * v1[2] - v0[2] * v1[1] ;
+  result[1] = v0[0] * v1[2] - v0[2] * v1[0] ;
+  result[2] = v0[0] * v1[1] - v0[1] * v1[0] ;
+  result[3] = 1;
+}
+
+// 内積
+float ps2_vu0_inner_product(FVECTOR v0, FVECTOR v1)
+{
+  return v0[0] * v1[0] + v0[1] * v1[1] + v0[2] * v1[2];
+}
+
+
+void ps2_vu0_mul_matrix(FMATRIX result, FMATRIX m0, FMATRIX m1)
+{
+  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];
+  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];
+  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];
+  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];
+
+  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];
+  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];
+  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];
+  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];
+
+  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];
+  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];
+  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];
+  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];
+
+  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];
+  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];
+  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];
+  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];
+}
+
+
+void ps2_vu0_copy_matrix(FMATRIX transfer, FMATRIX pose)
+{
+  memcpy(transfer, pose, sizeof(FMATRIX));
+}
+
+void ps2util_obj_Free(OBJECT* obj)
+{
+  free(obj);
+}
+
+
+
+void ps2_vu0_sub_vector(FVECTOR result, FVECTOR v0, FVECTOR v1)
+{
+  result[0] = v0[0] - v1[0];
+  result[1] = v0[1] - v1[1];
+  result[2] = v0[2] - v1[2];
+  result[3] = v0[3];// - v1[3];
+}
+
+
+
+void ps2_vu0_normalize(FVECTOR result, FVECTOR v)
+{
+  // 大きさで割ってるだけって
+  float d = sqrtf(v[0] * v[0] + v[1] * v[1] + v[2] * v[2]);
+  result[0] = v[0] / d;
+  result[1] = v[1] / d;
+  result[2] = v[2] / d;
+  result[3] = 1;
+}
+
+
+void xml_free(PolygonInfo xml)
+{
+  //none
+}
+
+
+void ps2util_obj_Draw(OBJECT *object)
+{
+  //none
+}
+
+
+void  ps2util_sprite_Destroy(ps2utilSprite *title_sprite )
+{
+  //none
+}
+
+
+
+
+void ps2util_sprite_Set_basicAttribute(ps2utilSprite *p,
+	unsigned short x, unsigned short y,
+	unsigned short sptable_tw1, unsigned short sptable_th1,
+	unsigned short sptable_tx, unsigned short sptable_ty,
+	unsigned short sptable_tw2, unsigned short sptable_th2,
+	int sprite_prio_foreground)
+{
+  //none
+}
+
+void ps2util_sprite_Request(ps2utilSprite *p)
+{
+  //none
+}
+
+
+void ps2util_sprite_Unuse_alpha(ps2utilSprite *sp)
+{
+  //none
+}
+
+void ps2util_graphic_Init()
+{
+  //none
+}
+
+
+/*
+  ps2 依存関係の sprite.c より引用。
+*/
+#define SPRITE_HAS_4VERTEXIS 4
+
+#define PS2_GS_XYZ3 1 // なにかわからん定数だから適当に作りました
+
+void
+sprite_disappear( SPRITE* sprite )
+{
+  int i;
+  GsSpritePacket* packet = sprite->gs_packet;
+  for (i=0; i<SPRITE_HAS_4VERTEXIS; i++)
+    packet->primData[i].xyz_addr = PS2_GS_XYZ3;
+}
+
+
+
+
+/*
+  からの関数
+  ps2 依存関係にあったけど、( name_dictionary.c ) の中のもの
+  だけど、他にも持ってくるものが増えるので、とりあえず、からの関数に
+*/
+void delete_name_dictionary(const char *string)
+{
+  /*
+  int number;
+  NAME_DIC *dic_ptr;
+
+  if (string == NULL) return;
+
+  number = hash_func(string,NAME_HASH_SIZE);
+
+  for (dic_ptr=name_hash+number;dic_ptr->name;dic_ptr=name_hash+number) {
+    if (!strcmp(string,dic_ptr->name)) {
+      dic_ptr->ref_num--;
+      if (dic_ptr->ref_num == 0) {
+	free(dic_ptr->name);
+	dic_ptr->name = NULL;
+      }
+      return;
+    } else {
+      number += REHASH_NUM;
+      if (number > NAME_HASH_SIZE) number -= NAME_HASH_SIZE;
+    }
+  }
+  */
+}
+  
+
+
+/*
+  ps2 依存関係から持ってきた。
+  テクスチャに割り振ったメモリの解放処理?
+  元ファイル:texture.c
+*/
+void free_texture(TEXTURE *tex)
+{
+  if (tex == NULL) return;
+
+  delete_name_dictionary(tex->name);
+  free(tex->free_texenv);
+  free(tex->free_image);
+  free(tex);
+}
+
+
+/*
+  ps2 依存関係内の、texture.c から拝借
+  この malloc によるメモリ取得をあちこちで行っているっぽい
+  cerium にある。
+*/
+int malloc_align16(void *free, void *aligned, int size)
+{
+  char *index;
+  unsigned int *f=(unsigned int *)free,*a=(unsigned int *)aligned;
+
+  if (free == NULL || aligned == NULL || size <= 0) return(-1);
+
+  index = (char *)malloc(size + ALIGN_16BYTE);
+  if (index == NULL) {
+    return(-1);
+  }
+
+  *f = *a = (unsigned long int)index;
+  if (((unsigned long int)index % ALIGN_16BYTE) != 0) {
+    index += ALIGN_16BYTE - ((unsigned long int)index % ALIGN_16BYTE);
+    *a = (unsigned long int)index;
+  }
+
+  return(0);
+}
+
+
+
+// miya
+void ps2util_tex_Exclude( TEXTURE* t )
+{
+  char *miyahira;
+  miyahira = "なにこの関数?";
+}
+
+void ps2util_sprite_Draw()
+{
+  printf("ps2util_sprite_Draw()\n");
+}
+
+void ps2util_graphic_Finish()
+{
+  printf("ps2util_graphic_Finish()\n");
+}
+
+
+// title.cに書いてた
+void ps2util_sprite_Use_alpha( ps2utilSprite *title )
+{
+  printf("ps2util_sprite_Use_alpha()\n");
+}