⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 spharm.c

📁 psp开发用的所有头文件。包含所有系统API。需要psp-gcc编译器。在www.psp-dev.com上有
💻 C
📖 第 1 页 / 共 2 页
字号:
      verts->ny = n.y;      verts->nz = n.z;      verts++;#if 0 // slower      memcpy(verts,prevptr,sizeof(struct Vertex));      memcpy(prevptr,verts-1,sizeof(struct Vertex));      verts++;#else      //  Add previous point to our list      verts->u  = prevptr->u;      verts->v  = prevptr->v;      verts->color = prevptr->color;      verts->x = prevptr->x;      verts->y = prevptr->y;      verts->z = prevptr->z;      verts->nx = prevptr->nx;      verts->ny = prevptr->ny;      verts->nz = prevptr->nz;      verts++;      //  Save this point as previous      prevptr->u  = texy;      prevptr->v  = texx;      if (color)        prevptr->color = 0xff000020 | (((int)coly)<< 16) | (((int)colx)<<8);      else        prevptr->color = 0xff555555;      prevptr->x = q.x;      prevptr->y = q.y;      prevptr->z = q.z;      prevptr->nx = n.x;      prevptr->ny = n.y;      prevptr->nz = n.z;#endif      //  Move previous pointer on      prevptr++;      colx += dcolx;    }    coly += dcoly;  }}extern unsigned char logo2_start[];extern unsigned char logo3_start[];unsigned char *logo2_temp;unsigned char *logo3_temp;static int rendertype;ScePspFVector3 columns[4] = {       { 0.707f, 0.707f, 0.0f },   // cos(a), sin(a), tx       { -0.707f, 0.707f, 0.0f },  // -sin(a), cos(a), ty       { 0.86f, 0.5f, 0.0f },       { -0.5f, 0.86f, 0.0f }    }; static ScePspFVector3 lpos = {0.0f,0.0f,1.0f};static ScePspFVector3 lpos1 = {0.0f,1.0f,0.0f};static ScePspFVector3 lpos2 = {1.0f,0.0f,0.0f};// converts the image and uploads it to vram in one go#define VRAM_OFFSET ((512*280*4)*3)// 0x198000static unsigned int vramaddr = 0;unsigned char *convertimage(unsigned char *inptr,int size){  // convert our raw image  // saved as raw. no header .. interleaved and order RGB  int x;  unsigned char *input = inptr;  unsigned char *output,*outptr;  int tsize = size*size;  if (vramaddr == 0)    vramaddr = (0x40000000 | (u32) sceGeEdramGetAddr()) + VRAM_OFFSET;  outptr = output = (unsigned char *)vramaddr;  for (x=0;x<tsize;x++) {    *(outptr++) = *(input++)/2;    *(outptr++) = *(input++)/2;    *(outptr++) = *(input++)/2;    *(outptr++) = 0xff;  }  vramaddr += tsize * 4;  if ((vramaddr & 0xff) != 0)    vramaddr = (vramaddr & 0xffffff00) + 0x100;  return output;}#define GU_UV_MAP     0#define GU_PROJ_MAP   1#define GU_ENV_MAP  2void set_rendermode(int mode, int *color){  int textured = 0;  int lit = 0;  int color2 = 0;  int envmap = 0;  //  Initial Setup  sceGuShadeModel(1);	sceGuEnable(GU_CLIP_PLANES);	sceGuDisable(GU_CULL_FACE);  sceGuDepthFunc(GU_GEQUAL);  sceGuEnable(GU_DEPTH_TEST);  sceGuDisable(GU_TEXTURE_2D);  sceGuDisable(GU_LIGHTING);  sceGuDisable(GU_LIGHT0);  sceGuDisable(GU_LIGHT1);  sceGuDisable(GU_LIGHT2);  sceGuDisable(GU_LIGHT3);  switch(mode) {    default:    case 0: //  Linestrips, no texture, colored and lit      color2 = 1;      break;    case 1: //  Plain colors, no texture      color2 = 1;      break;    case 2: //  Plain, lit, no texture      lit = 1;      break;    case 3: //  Textured      textured = 1;      sceGuTexMapMode(GU_UV_MAP,0,0);      break;    case 4: //  Textured, colored, no lights      color2 = 1;      textured = 1;      sceGuTexMapMode(GU_UV_MAP,0,0);      break;    case 5: //  Textured, lit      textured = 1;      lit = 1;      sceGuTexMapMode(GU_UV_MAP,0,0);      break;    case 6: //  Textured, envmap      textured = 1;      envmap = 1;      break;    case 7: //  Textured, envmap      textured = 2;      envmap = 1;      break;    case 8: //  Textured, envmap, vertex colors      color2 = 1;      textured = 2;      envmap = 1;      break;    case 9: //  Linestrips, no texture, colored and lit      textured = 2;      envmap = 1;      break;  }  if (envmap == 1) {    sceGuEnable(GU_LIGHTING);    sceGuEnable(GU_LIGHT0);    sceGuEnable(GU_LIGHT1);    sceGuEnable(GU_LIGHT2);    sceGuEnable(GU_LIGHT3);    sceGuLight( 0, GU_DIRECTIONAL, GU_DIFFUSE, &columns[0] );     sceGuLight( 1, GU_DIRECTIONAL, GU_DIFFUSE, &columns[1] );     sceGuLight( 2, GU_DIRECTIONAL, GU_DIFFUSE, &columns[2] );     sceGuLight( 3, GU_DIRECTIONAL, GU_DIFFUSE, &columns[3] );     sceGuTexProjMapMode( 0 );     sceGuTexMapMode( GU_ENV_MAP, 0, 1 ); // rotate envmap 45 degrees   }  if (lit == 1) {    //  lighting    sceGuEnable(GU_LIGHTING);    sceGuEnable(GU_LIGHT0);    sceGuLight(0,GU_DIRECTIONAL,GU_DIFFUSE_AND_SPECULAR,&lpos);    sceGuLightColor(0,GU_DIFFUSE,0xff00a000);    sceGuLightColor(0,GU_SPECULAR,0xff00ff00);    sceGuLightAtt(0,0.0f,1.0f,0.0f);    sceGuEnable(GU_LIGHT1);    sceGuLight(1,GU_DIRECTIONAL,GU_DIFFUSE_AND_SPECULAR,&lpos1);    sceGuLightColor(1,GU_DIFFUSE,0xff0000a0);    sceGuLightColor(1,GU_SPECULAR,0xff0000ff);    sceGuLightAtt(1,0.0f,1.0f,0.0f);      sceGuEnable(GU_LIGHT2);    sceGuLight(2,GU_DIRECTIONAL,GU_DIFFUSE_AND_SPECULAR,&lpos2);    sceGuLightColor(2,GU_DIFFUSE,0xffa00000);    sceGuLightColor(2,GU_SPECULAR,0xffff0000);    sceGuLightAtt(2,0.0f,1.0f,0.0f);    sceGuSpecular(12.0f);    sceGuAmbient(0xff101010);  }  if (textured != 0) {    //  textures    sceGuEnable(GU_TEXTURE_2D);	  sceGuTexMode(GU_PSM_8888,0,0,0);    if (textured == 1) sceGuTexImage(0,128,128,128,logo2_temp);    else if (textured == 2) sceGuTexImage(0,256,256,256,logo3_temp);	  sceGuTexFunc(GU_TFX_ADD,GU_TCC_RGB);	  sceGuTexFilter(GU_LINEAR,GU_LINEAR);	  sceGuTexScale(1.0f,1.0f);	  sceGuTexOffset(0.0f,0.0f);	  sceGuAmbientColor(0xff101010);    sceGuTexSync();  }  *color = color2;}#define TIME_LEN 100#define TIME_PAUSE 100void SpharmGenTest(int rendermode){  static int inited = 0;  static int resx = 20; // up/dpwn  static int resy = 24; // round  static int count = TIME_LEN+TIME_PAUSE;  static int objtype = -1;  static int odd = 0;  static int initial = 0;  int color;  if (initial == 0) {    objgen_spharm_setparam(1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f,1.0f);    objgen_spharm_setparamg(0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f,0.0f);    initial = 1;    sgenrand(12345);    logo2_temp = convertimage(logo2_start,128);    logo3_temp = convertimage(logo3_start,256);  }  // Start list  sceGuStart(0,(unsigned int *)spharmlist);  set_rendermode(rendermode,&color);  {    int y;    //1int index = ((resx*2)-1);    int index = (resx*2);    int primtype = 4;    if (rendermode == 0) primtype = 2;    else if (rendermode == 9) primtype = 2;    int index2 = index;    if (odd) {      for (y=1;y<resy;y++)         sceGumDrawArray(primtype,PSP_GEVERT_SET(3,7,3,3,0,0),index2,0,&vertices[y * index]);    } else {       for (y=1;y<resy;y++)         sceGumDrawArray(primtype,PSP_GEVERT_SET(3,7,3,3,0,0),index2,0,&vertices2[y * index]);    }  }  sceKernelDcacheWritebackAll();  sceGuFinish();  if (count > (TIME_LEN+TIME_PAUSE)) {    inited = 0;  }  if (count <= TIME_LEN ) objgen_spharm_tick();  count++;  if (inited == 0) {    inited = 1;    objtype++;    // default    switch(objtype)    {    case 0:      break;    case 1:      objgen_spharm_setparamt(TIME_LEN,40.0f,1.0f,40.0f,1.0f,1.0f,1.0f,1.0f,1.0f);      break;    case 2:      objgen_spharm_setparamt(TIME_LEN,20.0f,2.0f,20.0f,1.0f,1.0f,1.0f,1.0f,1.0f);      break;    case 3:      objgen_spharm_setparamt(TIME_LEN,10.0f,2.0f,1.0f,2.0f,3.0f,2.0f,3.0f,2.0f);      break;    case 4:      objgen_spharm_setparamt(TIME_LEN,4.0f,2.0f,2.0f,2.0f,3.0f,2.0f,3.0f,2.0f);      break;    case 5:      objgen_spharm_setparamt(TIME_LEN,2.0f,4.0f,1.0f,2.0f,1.0f,2.0f,1.0f,4.0f);      break;    case 6:      objgen_spharm_setparamt(TIME_LEN,1.0f,6.0f,1.0f,3.0f,1.0f,3.0f,1.0f,6.0f);      break;    case 7:      objgen_spharm_setparamt(TIME_LEN,6.0f,3.0f,6.0f,3.0f,2.0f,3.0f,2.0f,3.0f);      break;#define RAND_MULT 30.0f    case 8: {      // random object      static float t1,t2,t3,t4,t5,t6,t7,t8;      t1 = genrand() * 6.0f;  t1 = floorf(t1);      t2 = genrand() * 6.0f;  if (t2 == 0.0f) t2 += 0.02f;      t3 = genrand() * 6.0f;  t3 = floorf(t3);      t4 = genrand() * 6.0f;  if (t4 == 0.0f) t4 += 0.02f;      t5 = genrand() * 6.0f;  t5 = floorf(t5);      t6 = genrand() * 6.0f;  if (t6 == 0.0f) t6 += 0.02f;      t7 = genrand() * 6.0f;  t7 = floorf(t7);      t8 = genrand() * 6.0f;  if (t8 == 0.0f) t8 += 0.02f;      objgen_spharm_setparamt(TIME_LEN,t1,t2,t3,t4,t5,t6,t7,t8);      objtype--;// make sure we end up back in same spot      //objtype = 6; // make sure we end up back in same spot            } break;    default:  // none found, so move to next one, and trigger re-gen      objtype == 0;      inited = 0;      break;    }    count = 0;  }  if (odd) {    SparmGenList(vertices2,resx,resy,color);    odd = 0;  }  else {    SparmGenList(vertices,resx,resy,color);    odd = 1;  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -