diff gSprite.h @ 116:ed702e49cc6c

conpile
author e085768
date Thu, 16 Jun 2011 04:05:33 +0900
parents 31dd5c07f7c1
children f2e2460b4011
line wrap: on
line diff
--- a/gSprite.h	Wed Jun 15 23:31:59 2011 +0900
+++ b/gSprite.h	Thu Jun 16 04:05:33 2011 +0900
@@ -1,290 +1,33 @@
-//SgoexCerium.ccより
-#include "matrix_calc.h"
-#include "TaskManager.h"
-#include "SceneGraph.h"
-#include "Application.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "libps2.h"
-#include "ps2util.h"
-#include <stdbool.h>
-
-#define DEFOBJ 100
-#define SPRITE_COL 0x4f
-#define SCREEN_HALF_W 320
-#define SCREEN_HALF_H 240
-
-static SpriteTable   sptable[DEFOBJ];
-static ps2utilSprite sp[DEFOBJ]; // 表示スプライト用スタック
-static unsigned int  sp_counter;
-static bool          flag_spriteInited = false; // スプライトロードフラグ
-
-static TEXTURE *sprite_tex;
-
-
-
-extern Viewer *droot;
+#ifndef GSPRITE_H
+#define GSPRITE_H
 
-static SceneGraphPtr root;
-
-
-//SgoexCerium.ccより
-void
-flip()
-{
-    CameraPtr camera = droot->sgroot->getCamera();
-
-    droot->sgroot->flip();
-    droot->sgroot->lightCalc();
-
-    root = droot->createSceneGraph();
-    //root->xyz[0] = screen_w/2;
-    //root->xyz[1] = screen_h/2;;
-    root->xyz[0] = 0;
-    root->xyz[1] = 0;
-    root->xyz[2] = 30.0f;
-
-    /*親の回転、座標から、子の回転、座標を算出*/
-    get_matrix(root->matrix, root->angle, root->xyz, camera->matrix);
-    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-    get_matrix(root->real_matrix, root->angle, root->xyz, camera->real_matrix);
-    //出力して、次のものを出力するための準備
-    droot->setSceneData(root);
-}
-
-
-
-
+//スプライトの優先順位らしい ?
+#define SPRITE_PRIO_FOREGROUND 1
 
-/*void
-gSprite_DefSprite(int number, int tx, int ty, int tw, int th)
-{
-  sptable[number].tx = tx;
-  sptable[number].ty = ty;
-  sptable[number].tw = tw;
-  sptable[number].th = th;
-}*/
-void
-gSprite_DefSprite(int number, const char *name, float w, float h, int color, OBJECT *obj)
-{
-    SpriteTable *m = &sptable[number];
-    m->w = w;
-    m->h = h;
-    m->color = (color & 32);
-    m->mx = w / 2; //画像の中心を座標としたいらしい。
-    m->my = h / 2;
-    m->tex_w = power_of_two(m->w);
-    m->tex_h = power_of_two(m->h);
-    m->texture = (int *)name;
-
-}
-
-
-
-
-
-/*void
-gSprite_PutSprite(int number, int x, int y)
-{
-    ps2utilSprite *p = &sp[sp_counter];
-
-    ps2util_sprite_Set_basicAttribute(
-	p,
-	(unsigned short)x, (unsigned short)y,
-	(unsigned short)sptable[number].tw*2, (unsigned short)sptable[number].th*2,
-	(unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
-	(unsigned short)sptable[number].tw, (unsigned short)sptable[number].th,
-	SPRITE_PRIO_FOREGROUND);
-
-    ps2util_sprite_Request(p);
-    sp_counter++;
-}*/
-void
-gSprite_PutSprite(int number, short x, short y, int zorder)
-{
-    SpriteTable *m = &sptable[number];
-    char *name = (char *) m->texture;
-if (!name) {
-    printf("PutSprite %d unknown\n",number);
-    return;
-}
-    SceneGraphPtr object = droot->createSceneGraph(name);
-    //object->c_xyz[0] = m->mx;
-    //object->c_xyz[1] = m->my;
-    root->addChild(object);
-
-    object->xyz[0] -= object->c_xyz[0]*my_scale;
-    object->xyz[1] -= object->c_xyz[1]*my_scale;
-    object->xyz[2] -= object->c_xyz[2];
-
-    object->xyz[0] += x+m->mx;
-    object->xyz[1] += y+m->my;
-    object->xyz[2] += zorder * 0.01;
-
-    float scale[] = {my_scale,my_scale,1};
-    //float c_xyz[] = {0,0,0};
-    //scale_matrix(object->matrix, scale, c_xyz);
-
-    /*親の回転、座標から、子の回転、座標を算出*/
-    //get_matrix_scale(object->matrix, object->angle, object->xyz, scale, root->matrix);
-
-    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-    // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix);
-}
-
-
-
+typedef struct SpriteTable {
+  short dx;
+  short dy;
+  short w;
+  short h;
+  short mx;
+  short my;
+  int color;
+  int page;
+  int tex_w;
+  int tex_h;
+  int *texture;
+  int tex_id;  // for open gl                                                                                        
+} SpriteTable;
 
 
 
-/*void
-gSprite_PutSpriteEx(int number, int x, int y, float w, float h)
-{
-    ps2utilSprite *p = &sp[sp_counter];
-
-    ps2util_sprite_Set_basicAttribute(
-	p,
-	(unsigned short)x, (unsigned short)y,
-	(unsigned short)sptable[number].tw*w, (unsigned short)sptable[number].th*h,
-	(unsigned short)sptable[number].tx, (unsigned short)sptable[number].ty,
-	(unsigned short)sptable[number].tw, (unsigned short)sptable[number].th,
-	SPRITE_PRIO_FOREGROUND);
-
-    ps2util_sprite_Request(p);
-    sp_counter++;
-}*/
-void
-PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle)
-{
- if (1) {
-    PutSprite(1, x, y, number);
-    return;
- }
-
-    SpriteTable *m = &sptable[number];
-    char *name = (char *) m->texture;
-if (!name) {
-    printf("PutSpriteEx %d unknown\n",number);
-    return;
-}
-    SceneGraphPtr object = droot->createSceneGraph(name);
-    root->addChild(object);
-
-    float scale[] = {my_scale*scalex*4,my_scale*scaley*4,1};
-
-    /*親の回転、座標から、子の回転、座標を算出*/
-    object->xyz[0] = x - object->c_xyz[0] * my_scale - m->w*my_scale;
-    object->xyz[1] = y - object->c_xyz[1] * my_scale - m->h*my_scale;
-    object->xyz[2] = number * 0.01;
-    //object->c_xyz[0] = m->mx;
-    //object->c_xyz[1] = m->my;
-    object->angle[3] = angle * (3.1415926*2/4096);
-    get_matrix(object->matrix, object->angle, object->xyz, root->matrix);
-    float c_xyz[] = {0,0,0};
-    scale_matrix(object->matrix, scale, c_xyz);
-    /*法線用の行列。Cameraの行列を抜いている(Cameraのコンストラクタで、単位行列にしている)*/
-    // get_matrix(object->real_matrix, object->angle, object->xyz, root->real_matrix);
-}
-
-
-
-
-
-
-
-//ここいらはどうやら、スプライトを取得する部分。
-
-static void
-gSprite_Init_Png(const char *texname)
-{
-  if (!(sprite_tex = read_png_file(texname))) {
-    fprintf(stderr,
-	    "cannot creat texture - init_png().\n");
-    fflush(stderr);
-    exit(EXIT_FAILURE);
-  }
-
-  if (ps2util_tex_Set(sprite_tex) == -1) {
-    fprintf(stderr,
-	    "cannot set texture - init_png().\n");
-    fflush(stderr);
-    exit(EXIT_FAILURE);
-  }
+// extern とってみたけど、なにか不都合ありますか?:miya
+void gSprite_Init();
+void gSprite_Draw_Reset();
+void gSprite_PutSprite(int number, int x, int y);
+//void gSprite_PutSpriteEx(int number, int x, int y, float w, float h);
+void gSprite_PutSpriteEx(int number, int x, int y, float scalex, float scaley, float angle);
+//void gSprite_DefSprite(int number, int tx, int ty, int tw, int th);
+void gSprite_DefSprite(int number, const char *name, float w, float h, int color);//, OBJECT *obj);
 
-}
-
-static void
-gSprite_Create()
-{
-  int i;
-
-  for (i=0; i<DEFOBJ; i++) {
-    if (ps2util_sprite_Create(&sp[i], sprite_tex) == -1) {
-      fprintf(stderr,
-	      "cannot create sprite No.%d - create_sprite()\n", i);
-      fflush(stderr);
-      exit(EXIT_FAILURE);
-    }
-    ps2util_sprite_Unuse_alpha(&sp[i]);
-  }
-
-  flag_spriteInited = false;
-}
-
-
-void
-gSprite_Init()
-{
-  ps2util_graphic_Init();
-  //gSprite_Init_Png("img/main2.png");
-  //gSprite_Create(); // スプライト生成
-  
-  sgroot->createFromXMLfile("./xml_files/boss.xml");
- 
-  /*  gSprite_DefSprite(10,   1,   1, 512, 666); // タイトル  
-  gSprite_DefSprite(17,   1,  35,  33,  33); // 選択マーク
-  gSprite_DefSprite(23,   1,   1, 106,  34); // スピードメーター
-  gSprite_DefSprite(24,  51,  40,  18,  20); // 右矢印
-  gSprite_DefSprite(25,  33,  40,  17,  20); // 左矢印
-  gSprite_DefSprite(26,  56,  89,  55,  26); // km/h
-  gSprite_DefSprite(27,  62,  62,  39,  26); // Rap
-  gSprite_DefSprite(28, 430,  62,  53,  46); // 1p
-  gSprite_DefSprite(29, 460,   6,  53,  46); // 2P 
-  gSprite_DefSprite(51, 333, 116, 165,  140); // 選択画面の車 
-  gSprite_DefSprite(52, 181, 116, 165,  140);
-  gSprite_DefSprite(53,  12, 116, 165,  140);
-  gSprite_DefSprite(81, 115,   1, 148, 114); // 選択画面のコース 
-  // 本当は (82, 272,...)です。二つ目のコース絵がないので 
-  gSprite_DefSprite(82, 272,   1, 148, 114);*/
-
-}
-
-
-static void
-gSprite_Clear()
-{
-  int i;
-
-  for (i=0; i<DEFOBJ; i++) {
-    sprite_disappear(&sp[i].attribute);
-  }
-  sp_counter = 0;
-}
-
-
-
-void
-gSprite_Draw_Reset()
-{
-  if (flag_spriteInited == true) {
-    gSprite_Clear();
-  }
-}
-
-
-
-void
-gSprite_PutSprite_Pause()
-{
-}
+#endif