Browse Source

Some cleanup and comments.

master
Nico de Poel 3 years ago
parent
commit
592145e502
  1. 32
      main.c

32
main.c

@ -384,18 +384,19 @@ void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameC
int *scale = model->header->scale;
int *translate = model->header->translate;
// Model world position and rotation
MATRIX model_mtx;
RotMatrix(&model->rotation, &model_mtx);
TransMatrix(&model_mtx, &model->position);
// Adjust light direction by the model's rotation relative to the world
MATRIX light_mtx;
MulMatrix0(&light_dirs, &model_mtx, &light_mtx);
gte_SetLightMatrix(&light_mtx);
// Compose model matrix with view-projection matrix to obtain the final model-view-projection matrix
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);
@ -483,8 +484,6 @@ void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameC
addPrim(ot[db] + depth, poly);
nextpri += sizeof(POLY_GT3);
}
PopMatrix();
}
void drawStuff(int counter)
@ -498,29 +497,15 @@ void drawStuff(int counter)
// Draw the last created text stream
FntFlush(-1);
gte_SetBackColor(48, 48, 48); // Ambient light color
gte_SetBackColor(48, 48, 48); // Ambient light color
gte_SetColorMatrix(&light_cols); // Light color (up to three different lights)
// Expected order of things:
// - Initial scale matrix to correct aspect ratio
// - Coordinate system swizzle (scale) (can probably be combined with the above)
// - Camera inverse translation
// - Camera inverse rotation (apply on top of camera translation)
// - Multiply light matrix (lights will be in Quake coordinate system)
// - Push matrix
// - Entity local rotation
// - Entity local translation
// - Model internal scale
// - Model internal translate
// - Render
// - Pop matrix
MATRIX proj_matrix = quake_swizzle; // Swizzle coordinates so that everything is in Quake coordinate system (Z up)
MATRIX proj_matrix = quake_swizzle; // Swizzle coordinates so that everything is in Quake coordinate system (Z up)
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, 400, -100 }; // TODO: camera position (in Quake coordinates)
SVECTOR trot = { 0, 0, 0, 0 }; // TODO: inverse camera rotation (in Quake coordinates)
VECTOR tpos = { 0, 400, -100 }; // TODO: inverse 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
@ -528,9 +513,6 @@ void drawStuff(int counter)
// Compose view and projection matrices to obtain a combined view-projection matrix
CompMatrixLV(&proj_matrix, &view_matrix, &view_matrix);
gte_SetRotMatrix(&view_matrix);
gte_SetTransMatrix(&view_matrix);
drawModel(&view_matrix, &playerModel, &playerSkin, counter >> 2);
drawModel(&view_matrix, &shamblerModel, &shamblerSkin, counter >> 2);
}

Loading…
Cancel
Save