diff --git a/main.c b/main.c index 5853404..59d538e 100644 --- a/main.c +++ b/main.c @@ -76,8 +76,8 @@ typedef struct ps1texture_t front, back; } ps1skin_t; -ps1mdl_t playerModel = { .position = { -200, 200, -160 }, .rotation = { 0 } }; -ps1mdl_t shamblerModel = { .position = { 100, 200, -160 }, .rotation = { 0 } }; +ps1mdl_t playerModel = { .position = { -150, 0, 0 }, .rotation = { 0 } }; +ps1mdl_t shamblerModel = { .position = { 150, 0, 0 }, .rotation = { 0, 0, ONE >> 1, 0 } }; ps1skin_t playerSkin, shamblerSkin; const MATRIX identity = { @@ -368,6 +368,8 @@ static int fakeLight(const int *norm) SVECTOR outPos; +#define SCTR(v, i) (short)((scale[i]*(v)->position[i]+translate[i])>>10) + void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameCounter) { ps1texture_t *tex; @@ -391,9 +393,15 @@ void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameC gte_SetLightMatrix(&light_mtx); CompMatrixLV(view_matrix, &model_mtx, &model_mtx); - + PushMatrix(); + // TODO: this idea is good but it's missing the >> 12 fraction divide after transformation. Hmmmm... + // MATRIX mesh_mtx = identity; + // ScaleMatrixL(&mesh_mtx, (VECTOR*)scale); + // TransMatrix(&mesh_mtx, (VECTOR*)translate); + // CompMatrixLV(&model_mtx, &mesh_mtx, &mesh_mtx); + gte_SetRotMatrix(&model_mtx); gte_SetTransMatrix(&model_mtx); @@ -405,9 +413,12 @@ void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameC ps1mdl_vertex_t *v1 = &baseVert[tri->vertexIndex[1]]; ps1mdl_vertex_t *v2 = &baseVert[tri->vertexIndex[2]]; - SVECTOR pos0 = { v0->position[0], v0->position[1], v0->position[2], 0 }; - SVECTOR pos1 = { v1->position[0], v1->position[1], v1->position[2], 0 }; - SVECTOR pos2 = { v2->position[0], v2->position[1], v2->position[2], 0 }; + // SVECTOR pos0 = { v0->position[0], v0->position[1], v0->position[2], 0 }; + // SVECTOR pos1 = { v1->position[0], v1->position[1], v1->position[2], 0 }; + // SVECTOR pos2 = { v2->position[0], v2->position[1], v2->position[2], 0 }; + SVECTOR pos0 = { SCTR(v0,0), SCTR(v0,1), SCTR(v0,2), 0 }; + SVECTOR pos1 = { SCTR(v1,0), SCTR(v1,1), SCTR(v1,2), 0 }; + SVECTOR pos2 = { SCTR(v2,0), SCTR(v2,1), SCTR(v2,2), 0 }; gte_ldv3(&pos0, &pos1, &pos2); gte_rtpt(); // Rotation, Translation and Perspective triplet (all three vertices at once) @@ -508,8 +519,8 @@ void drawStuff(int counter) ScaleMatrixL(&proj_matrix, &aspect_scale); // Apply aspect ratio correction for the current resolution MATRIX view_matrix; - SVECTOR trot = { 0, 0, 0, 0 }; // TODO: camera rotation (in Quake coordinates) - VECTOR tpos = { 0, 0, 0 }; // TODO: camera position (in Quake coordinates) + SVECTOR trot = { 0, 0, 0, 0 }; // TODO: camera rotation (in Quake coordinates) + VECTOR tpos = { 0, 400, -100 }; // TODO: camera position (in Quake coordinates) RotMatrix(&trot, &view_matrix); // Set camera rotation part of the view matrix ApplyMatrixLV(&view_matrix, &tpos, &tpos); // Apply camera rotation to camera position TransMatrix(&view_matrix, &tpos); // Apply transformed position to the translation part of the view matrix @@ -536,6 +547,8 @@ int main(int argc, const char *argv[]) counter = 0; while(1) { + //playerModel.rotation.vz = (counter << 2) % ONE; + drawStuff(counter); // Update display