view ps2util.c @ 95:b0249b856488

change_ps2util
author Atuto SHIROMA <e095729@ie.u-ryukyu.ac.jp>
date Thu, 26 May 2011 18:13:40 +0900
parents cb6c6de125dc
children 0b65ca27f113
line wrap: on
line source

#include <stdio.h>
#include <stdlib.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
}


void ps2_vu0_copy_vector(FVECTOR directionA, FVECTOR directionB)
{
  //none
}


void ps2util_obj_Renew_transMatrix(OBJECT *car){
  //none
}


/*
  ps2 内の texture.c から
*/
TEXTURE* read_png_file(char *texname)
{
  //とりあえず戻り値を返してエラーをどうにか
  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;
}

void ps2_vu0_rot_matrix_y(FMATRIX result, FMATRIX m, float radian)
{
  FMATRIX rot;
  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] = fsign(radian);
  m[2][2] = fsign(radian);
  m[0][2] = -fcos(radian);
  m[2][0] = fcos(radian);

  FMATRIX m1 = m;

  ps2_vu0_mul_matrix(result, m1, m);
  
}


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];
}

void ps2_vu0_add_vector(FVECTOR car_location1, FVECTOR car_location2,FVECTOR mov)
{
  //none
}


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 pose1, FMATRIX yrot, FMATRIX pose2)
{
  //none
}

void ps2_vu0_copy_matrix(FMATRIX from, FMATRIX to)
{
  to = from;
}


void ps2util_tex_Exclude(TEXTURE* t)
{
  //none
}

void ps2util_obj_Free(OBJECT* obj)
{
  free(obj);
}



void ps2_vu0_sub_vector(FVECTOR o0, FVECTOR p, FVECTOR p0)
{
  //none
}




void ps2_vu0_normalize(FVECTOR result, FVECTOR v)
{
  float d = fsqrt(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 gSprite_Init()
{
  //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 より引用。
*/
inline 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);
}