diff --git a/CMakeLists.txt b/CMakeLists.txt index 564dd67..62db926 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,11 +13,12 @@ project( psn00bsdk_add_executable(template STATIC main.c) +psn00bsdk_target_incbin(template PRIVATE mdl_player player.ps1mdl) psn00bsdk_target_incbin(template PRIVATE tim_player_f player_f.tim) psn00bsdk_target_incbin(template PRIVATE tim_player_b player_b.tim) -psn00bsdk_target_incbin(template PRIVATE tim_player16bpp player128-16.tim) -psn00bsdk_target_incbin(template PRIVATE tim_shambler shambler128.tim) -psn00bsdk_target_incbin(template PRIVATE mdl_player player.ps1mdl) +psn00bsdk_target_incbin(template PRIVATE mdl_shambler shambler.ps1mdl) +psn00bsdk_target_incbin(template PRIVATE tim_shambler_f shambler_f.tim) +psn00bsdk_target_incbin(template PRIVATE tim_shambler_b shambler_b.tim) psn00bsdk_add_cd_image( iso # Target name diff --git a/main.c b/main.c index 8cc9612..581332c 100644 --- a/main.c +++ b/main.c @@ -42,19 +42,20 @@ int db; u_long ot[2][OTLEN]; // Ordering tables, two arrays for double buffering. These are basically the buckets for bucket sorting of polygons. // You can also see them as "layers" in the modern 3D graphics sense, but they serve a more immediate role for polygon ordering. -char primbuff[2][32768]; // Primitive buffer, just a raw buffer of bytes to use as a pool for primitives +char primbuff[2][65536]; // Primitive buffer, just a raw buffer of bytes to use as a pool for primitives char *nextpri; +extern u_long mdl_player[]; extern u_long tim_player_f[]; extern u_long tim_player_b[]; -extern u_long tim_player16bpp[]; -extern u_long tim_shambler[]; -extern u_long mdl_player[]; +extern u_long mdl_shambler[]; +extern u_long tim_shambler_f[]; +extern u_long tim_shambler_b[]; // The player texture is divided into two pieces, so that each part is aligned to their own texture page TIM_IMAGE playerFrontTex, playerBackTex; -TIM_IMAGE shamblerTex; -ps1mdl_t model; +TIM_IMAGE shamblerFrontTex, shamblerBackTex; +ps1mdl_t playerModel, shamblerModel; void loadTexture(const u_long* tim, TIM_IMAGE* tparam) { @@ -124,12 +125,13 @@ void init(void) nextpri = primbuff[0]; + loadModel(mdl_player, &playerModel); loadTexture(tim_player_f, &playerFrontTex); loadTexture(tim_player_b, &playerBackTex); - //loadTexture(tim_player16bpp, &playerFrontTex); - loadTexture(tim_shambler, &shamblerTex); - loadModel(mdl_player, &model); + loadModel(mdl_shambler, &shamblerModel); + loadTexture(tim_shambler_f, &shamblerFrontTex); + loadTexture(tim_shambler_b, &shamblerBackTex); // Set texture page for the entire drawing environment. Nice in some cases perhaps, but not what we need. //draw[0].tpage = getTPage(playerFrontTex.mode & 0x3, 0, playerFrontTex.prect->x, playerFrontTex.prect->y); @@ -289,33 +291,22 @@ static int fakeLight(const int *norm) return lit << 16 | lit << 8 | lit; } -void drawStuff(int counter) +void drawModel(ps1mdl_t *model, TIM_IMAGE *frontTex, TIM_IMAGE *backTex, int xOffset, int frameCounter) { - ClearOTagR(ot[db], OTLEN); - - // Print the obligatory hello world and counter to show that the - // program isn't locking up to the last created text stream - FntPrint(-1, "COUNTER=%d, SIN=%d\n", counter, isin(counter)); - FntPrint(-1, "Image x %d y %d w %d h %d mode 0x%x\n", playerFrontTex.prect->x, playerFrontTex.prect->y, playerFrontTex.prect->w, playerFrontTex.prect->h, playerFrontTex.mode); - FntPrint(-1, "Model: %d tris, %d verts\n", model.header->triangleCount, model.header->vertexCount); - - // Draw the last created text stream - FntFlush(-1); - - int frameNum = (counter >> 2) % model.header->frameCount; - int vertOffs = frameNum * model.header->vertexCount; + int frameNum = frameCounter % model->header->frameCount; + int vertOffs = frameNum * model->header->vertexCount; - for (int triIdx = 0; triIdx < model.header->triangleCount; ++triIdx) + for (int triIdx = 0; triIdx < model->header->triangleCount; ++triIdx) { - ps1mdl_triangle_t *tri = &model.triangles[triIdx]; + ps1mdl_triangle_t *tri = &model->triangles[triIdx]; - ps1mdl_vertex_t *v0 = &model.vertices[tri->vertexIndex[0] + vertOffs]; - ps1mdl_vertex_t *v1 = &model.vertices[tri->vertexIndex[1] + vertOffs]; - ps1mdl_vertex_t *v2 = &model.vertices[tri->vertexIndex[2] + vertOffs]; + ps1mdl_vertex_t *v0 = &model->vertices[tri->vertexIndex[0] + vertOffs]; + ps1mdl_vertex_t *v1 = &model->vertices[tri->vertexIndex[1] + vertOffs]; + ps1mdl_vertex_t *v2 = &model->vertices[tri->vertexIndex[2] + vertOffs]; - ps1mdl_texcoord_t *tc0 = &model.texCoords[tri->vertexIndex[0]]; - ps1mdl_texcoord_t *tc1 = &model.texCoords[tri->vertexIndex[1]]; - ps1mdl_texcoord_t *tc2 = &model.texCoords[tri->vertexIndex[2]]; + ps1mdl_texcoord_t *tc0 = &model->texCoords[tri->vertexIndex[0]]; + ps1mdl_texcoord_t *tc1 = &model->texCoords[tri->vertexIndex[1]]; + ps1mdl_texcoord_t *tc2 = &model->texCoords[tri->vertexIndex[2]]; // Use normal indices to generate a greyscale value. Good for just giving the polygons some gradients. unsigned int n0 = v0->normalIndex, n1 = v1->normalIndex, n2 = v2->normalIndex; @@ -337,18 +328,35 @@ void drawStuff(int counter) unsigned short depth = ((unsigned short)v0->position[1] + (unsigned short)v1->position[1] + (unsigned short)v2->position[1]) / 3; // Since we have the texture split into two parts, we need to correct the UVs that are *not* on the seam, instead of the other way round - short u0 = !tri->frontFace && !tc0->onSeam ? tc0->u - (model.header->skinWidth >> 1) : tc0->u; - short u1 = !tri->frontFace && !tc1->onSeam ? tc1->u - (model.header->skinWidth >> 1) : tc1->u; - short u2 = !tri->frontFace && !tc2->onSeam ? tc2->u - (model.header->skinWidth >> 1) : tc2->u; + short u0 = !tri->frontFace && !tc0->onSeam ? tc0->u - (model->header->skinWidth >> 1) : tc0->u; + short u1 = !tri->frontFace && !tc1->onSeam ? tc1->u - (model->header->skinWidth >> 1) : tc1->u; + short u2 = !tri->frontFace && !tc2->onSeam ? tc2->u - (model->header->skinWidth >> 1) : tc2->u; addGouraudTexturedTriangle( - v0->position[0], 240 - v0->position[2], - v1->position[0], 240 - v1->position[2], - v2->position[0], 240 - v2->position[2], + xOffset + v0->position[0], 240 - v0->position[2], + xOffset + v1->position[0], 240 - v1->position[2], + xOffset + v2->position[0], 240 - v2->position[2], (unsigned char)depth, rgb0, rgb1, rgb2, - u0, tc0->v, u1, tc1->v, u2, tc2->v, tri->frontFace ? &playerFrontTex : &playerBackTex); + u0, tc0->v, u1, tc1->v, u2, tc2->v, tri->frontFace ? frontTex : backTex); } +} + +void drawStuff(int counter) +{ + ClearOTagR(ot[db], OTLEN); + + // Print the obligatory hello world and counter to show that the + // program isn't locking up to the last created text stream + FntPrint(-1, "COUNTER=%d, SIN=%d\n", counter, isin(counter)); + FntPrint(-1, "Image x %d y %d w %d h %d mode 0x%x\n", playerFrontTex.prect->x, playerFrontTex.prect->y, playerFrontTex.prect->w, playerFrontTex.prect->h, playerFrontTex.mode); + FntPrint(-1, "Model: %d tris, %d verts\n", playerModel.header->triangleCount, playerModel.header->vertexCount); + + // Draw the last created text stream + FntFlush(-1); + + drawModel(&playerModel, &playerFrontTex, &playerBackTex, -40, counter >> 2); + drawModel(&shamblerModel, &shamblerFrontTex, &shamblerBackTex, 80, counter >> 2); return; @@ -363,7 +371,7 @@ void drawStuff(int counter) addColoredTriangle(260, 140, 220, 220, 300, 220, 0xFF0000, 0x00FF00, 0x0000FF, 0); addTexturedTriangle(260, 40, 220, 120, 300, 120, 0, 94, 74, 124, 58, 1, &playerFrontTex); addTexturedSprite(20, 140, 80, 80, &playerFrontTex); - addTexturedSprite(80, 40, 154, 114, &shamblerTex); + addTexturedSprite(80, 40, 154, 114, &shamblerFrontTex); } // Main function, program entrypoint diff --git a/shambler.ps1mdl b/shambler.ps1mdl new file mode 100644 index 0000000..d0ea380 Binary files /dev/null and b/shambler.ps1mdl differ diff --git a/shambler_b.tim b/shambler_b.tim new file mode 100644 index 0000000..6727904 Binary files /dev/null and b/shambler_b.tim differ diff --git a/shambler_f.tim b/shambler_f.tim new file mode 100644 index 0000000..59d6c19 Binary files /dev/null and b/shambler_f.tim differ