From 15201a547e8d6410741ca4a0e7916ff5f2cd31e5 Mon Sep 17 00:00:00 2001 From: Nico de Poel Date: Fri, 9 Sep 2022 13:27:24 +0200 Subject: [PATCH] Added model scale and translation, so that models have the correct relative sizes. --- main.c | 15 ++++++++++----- player.ps1mdl | Bin 125820 -> 125844 bytes ps1mdl.h | 3 +++ shambler.ps1mdl | Bin 57300 -> 57324 bytes 4 files changed, 13 insertions(+), 5 deletions(-) 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 66890daa15fb315bbdee0e6a40e3a2e87901061a..65bec19055067f7d381bb6ea2972ffb3570d564d 100644 GIT binary patch delta 46 zcmex!jeW{>b_GwD0Dm?H1_mu4Vb99IaGHgI;o#;!|1XOF{hws??|&o5Ru0CJ*8pVv B5o-Vd delta 22 dcmbPoo&C=>b`DRM0Dm?H28Kq3tqP1KuK`=%2V4LE 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 d0ea3807e9c8e26086c779771cf777be3f3b3e15..6dd0fe9208e718031decf51e489f5540eb81d837 100644 GIT binary patch delta 43 zcmV+`0M!4~zXR;Q10YF6P)`N`0009D000yV006}Z004F_`~P+s`~TNI{{OKE%-