// PA_md2 Loader by jandujar
// Based on Webez md2 loader (gbadev)
#include <PA9.h> // Include for PA_Lib
#include "tris_md2.h"
#include "eva_pcx.h"
#include "PA_md2.hpp"
// Estructura un punto en 3D
typedef struct{
float x;
float y;
float z;
}miVector;
miVector camara;
miVector mira;
// Function: main()
int main(int argc, char ** argv)
{
u8 animation=9;
PA_Init(); // Initializes PA_Lib
PA_InitVBL(); // Initializes a standard VBL
PA_InitText(1,0);
PA_Init3D();
PA_md2* eva;
eva=new PA_md2();
u16 frame=0;
u16 nframe=0;
mira.x=0.0;
mira.y=0.0;
mira.z=0.0;
camara.x=7.0;
camara.z=0.0;
camara.y=0.0;
eva->PA_md2_load(tris_md2,eva_pcx);
eva->PA_md2_set_animation(animation); //Set up the animation
PA_OutputText(1,0,0,"Animation %d ",animation);
// Infinite loop to keep the program running
while (1)
{
PA_Init3DDrawing(camara.x,camara.y,camara.z,mira.x,mira.y,mira.z);
eva->PA_md2_animate(1); // Animate the frame
if(Pad.Released.A){animation++; PA_OutputText(1,0,0,"Animation %d ",animation);eva->PA_md2_set_animation(animation);}
if(Pad.Released.B){animation--;PA_OutputText(1,0,0,"Animation %d ",animation);eva->PA_md2_set_animation(animation);}
glColor3b(255,255,255); //If I not put colors the texture does not show
eva->PA_md2_draw();
glFlush();
PA_WaitForVBL();
}
return 0;
} // End of main()
void DS_3DObject::createDisplayList(){
displayList.push_back(2+mesh->polIndex.size()*11);
displayList.push_back(FIFO_COMMAND_PACK(FIFO_NOP, FIFO_NOP, FIFO_NOP, FIFO_BEGIN));
displayList.push_back(GL_TRIANGLE);
for(unsigned int i = 0; i < mesh->polIndex.size(); i++){
displayList.push_back(FIFO_COMMAND_PACK(FIFO_NORMAL,FIFO_COLOR,FIFO_TEX_COORD,FIFO_VERTEX16));
displayList.push_back(NORMAL_PACK( 0, 1<<9, 0));
displayList.push_back(RGB15(colors[i]->red>>3,colors[i]->green>>3,colors[i]->blue>>3));
displayList.push_back(TEXTURE_PACK(mesh->maps[mesh->mapIndex[i]->indexA]->u,mesh->maps[mesh->mapIndex[i]->indexA]->v));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexA]->x,mesh->vertex[mesh->polIndex[i]->indexA]->y));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexA]->z,0));
displayList.push_back(FIFO_COMMAND_PACK(FIFO_TEX_COORD,FIFO_VERTEX16,FIFO_TEX_COORD,FIFO_VERTEX16));
displayList.push_back(TEXTURE_PACK(mesh->maps[mesh->mapIndex[i]->indexB]->u,mesh->maps[mesh->mapIndex[i]->indexB]->v));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexB]->x,mesh->vertex[mesh->polIndex[i]->indexB]->y));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexB]->z,0));
displayList.push_back(TEXTURE_PACK(mesh->maps[mesh->mapIndex[i]->indexC]->u,mesh->maps[mesh->mapIndex[i]->indexC]->v));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexC]->x,mesh->vertex[mesh->polIndex[i]->indexC]->y));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexC]->z,0));
}
displayList.push_back(FIFO_COMMAND_PACK(FIFO_NOP, FIFO_NOP, FIFO_NOP, FIFO_END));
}
webez escribió:La funcion de loadLevel la puedes quitar porque es para cargar niveles de un editor que estoy haciendo y las 2 read tambien porque son para esa funcion.
Sobre las display list lo que ya dije, con interpolación está chungo, porque hay que cambiar obtener los vértices de dentro de las listas. De todos modos si no se usa interpolación se puede usar esta funcionvoid DS_3DObject::createDisplayList(){
displayList.push_back(2+mesh->polIndex.size()*11);
displayList.push_back(FIFO_COMMAND_PACK(FIFO_NOP, FIFO_NOP, FIFO_NOP, FIFO_BEGIN));
displayList.push_back(GL_TRIANGLE);
for(unsigned int i = 0; i < mesh->polIndex.size(); i++){
displayList.push_back(FIFO_COMMAND_PACK(FIFO_NORMAL,FIFO_COLOR,FIFO_TEX_COORD,FIFO_VERTEX16));
displayList.push_back(NORMAL_PACK( 0, 1<<9, 0));
displayList.push_back(RGB15(colors[i]->red>>3,colors[i]->green>>3,colors[i]->blue>>3));
displayList.push_back(TEXTURE_PACK(mesh->maps[mesh->mapIndex[i]->indexA]->u,mesh->maps[mesh->mapIndex[i]->indexA]->v));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexA]->x,mesh->vertex[mesh->polIndex[i]->indexA]->y));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexA]->z,0));
displayList.push_back(FIFO_COMMAND_PACK(FIFO_TEX_COORD,FIFO_VERTEX16,FIFO_TEX_COORD,FIFO_VERTEX16));
displayList.push_back(TEXTURE_PACK(mesh->maps[mesh->mapIndex[i]->indexB]->u,mesh->maps[mesh->mapIndex[i]->indexB]->v));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexB]->x,mesh->vertex[mesh->polIndex[i]->indexB]->y));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexB]->z,0));
displayList.push_back(TEXTURE_PACK(mesh->maps[mesh->mapIndex[i]->indexC]->u,mesh->maps[mesh->mapIndex[i]->indexC]->v));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexC]->x,mesh->vertex[mesh->polIndex[i]->indexC]->y));
displayList.push_back(VERTEX_PACK(mesh->vertex[mesh->polIndex[i]->indexC]->z,0));
}
displayList.push_back(FIFO_COMMAND_PACK(FIFO_NOP, FIFO_NOP, FIFO_NOP, FIFO_END));
}
Aunque está sólo probada con los modelos de 3dstudio que no les pongo texturas.
displaList es un vector de u32. De todos modos igual falta alguna cosilla de las nuevas clases. En posteriores versiones también quitaré la clase DS_3D pues aunque quería conseguir indepencia entre implementación y estructura no lo veo factible.
Una pena que con lo bien que quedan tengan una utilidad tan limitada. ¿Alguien se anima a poner las normales? (es que me da un palo trastear con la luz...)
Un saludo.
PD: No consigo que se vea mejor la función
jandujar