diff --git a/main.c b/main.c index f0b6d94..94e6713 100644 --- a/main.c +++ b/main.c @@ -78,8 +78,8 @@ typedef struct ps1texture_t front, back; } ps1skin_t; -ps1mdl_t playerModel = { .position = { -200, 128, 64 }, .rotation = { 0 } }; -ps1mdl_t shamblerModel = { .position = { -64, 96, 64 }, .rotation = { 0 } }; +ps1mdl_t playerModel = { .position = { -128, 320, 400 }, .rotation = { 0 } }; +ps1mdl_t shamblerModel = { .position = { 128, 320, 400 }, .rotation = { 0 } }; ps1skin_t playerSkin, shamblerSkin; MATRIX color_mtx = { @@ -369,6 +369,9 @@ void drawModel(ps1mdl_t *model, ps1skin_t *skin, int xOffset, int frameCounter) int vertOffs = frameNum * model->header->vertexCount; short halfSkinWidth = model->halfSkinWidth; + int *scale = model->header->scale; + int *translate = model->header->translate; + for (int triIdx = 0; triIdx < model->header->triangleCount; ++triIdx) { ps1mdl_triangle_t *tri = &model->triangles[triIdx]; @@ -378,9 +381,11 @@ void drawModel(ps1mdl_t *model, ps1skin_t *skin, int xOffset, int frameCounter) ps1mdl_vertex_t *v2 = &model->vertices[tri->vertexIndex[2] + vertOffs]; // Swizzle the coordinates because Quake Z is up - SVECTOR pos0 = { v0->position[0], -v0->position[2], v0->position[1] }; - SVECTOR pos1 = { v1->position[0], -v1->position[2], v1->position[1] }; - SVECTOR pos2 = { v2->position[0], -v2->position[2], v2->position[1] }; + // TODO: scale and translate should be done by the GTE instead of through software here + // Finding the appropriate scale range here is tricky. Normalize with >> 12 as usual and the coordinates become so small that you lose depth precision. + SVECTOR pos0 = { (v0->position[0] * scale[0] + translate[0]) >> 10, (-v0->position[2] * scale[2] + translate[2]) >> 10, (v0->position[1] * scale[1] + translate[1]) >> 10 }; + SVECTOR pos1 = { (v1->position[0] * scale[0] + translate[0]) >> 10, (-v1->position[2] * scale[2] + translate[2]) >> 10, (v1->position[1] * scale[1] + translate[1]) >> 10 }; + SVECTOR pos2 = { (v2->position[0] * scale[0] + translate[0]) >> 10, (-v2->position[2] * scale[2] + translate[2]) >> 10, (v2->position[1] * scale[1] + translate[1]) >> 10 }; gte_ldv3(&pos0, &pos1, &pos2); gte_rtpt(); // Rotation, Translation and Perspective triplet (all three vertices at once) diff --git a/player.ps1mdl b/player.ps1mdl index 66890da..65bec19 100644 Binary files a/player.ps1mdl and b/player.ps1mdl differ diff --git a/ps1mdl.h b/ps1mdl.h index 487dc56..9ffb124 100644 --- a/ps1mdl.h +++ b/ps1mdl.h @@ -10,6 +10,9 @@ typedef struct int ident; int version; + int scale[3]; + int translate[3]; + unsigned short skinWidth; unsigned short skinHeight; diff --git a/shambler.ps1mdl b/shambler.ps1mdl index d0ea380..6dd0fe9 100644 Binary files a/shambler.ps1mdl and b/shambler.ps1mdl differ