Browse Source

Reorganized code so that each model can have its own position and rotation. Added the Shambler model back in.

master
Nico de Poel 3 years ago
parent
commit
92a3607fe5
  1. 36
      main.c

36
main.c

@ -60,6 +60,9 @@ typedef struct
ps1mdl_vertex_t* vertices;
short halfSkinWidth; // Used for offsetting UVs on the back texture
VECTOR position;
SVECTOR rotation;
} ps1mdl_t;
typedef struct
@ -75,12 +78,10 @@ typedef struct
ps1texture_t front, back;
} ps1skin_t;
ps1mdl_t playerModel, shamblerModel;
ps1mdl_t playerModel = { .position = { -200, 128, 64 }, .rotation = { 0 } };
ps1mdl_t shamblerModel = { .position = { -64, 96, 64 }, .rotation = { 0 } };
ps1skin_t playerSkin, shamblerSkin;
SVECTOR rot = { 0 };
VECTOR pos = { -200, 128, 64 };
MATRIX color_mtx = {
ONE, 0, 0,
ONE, 0, 0,
@ -157,10 +158,12 @@ void init(void)
SetDefDrawEnv(&draw[1], 0, 0, SCREENWIDTH, SCREENHEIGHT);
// Set and enable clear color
setRGB0(&draw[0], 96, 0, 96);
setRGB0(&draw[1], 96, 0, 96);
setRGB0(&draw[0], 49, 77, 121);
setRGB0(&draw[1], 49, 77, 121);
draw[0].isbg = 1;
draw[0].dtd = 1;
draw[1].isbg = 1;
draw[1].dtd = 1;
// Clear double buffer counter
db = 0;
@ -353,6 +356,15 @@ void drawModel(ps1mdl_t *model, ps1skin_t *skin, int xOffset, int frameCounter)
short u0, u1, u2, uoffs, voffs;
int p;
MATRIX mtx, lmtx;
RotMatrix(&model->rotation, &mtx);
TransMatrix(&mtx, &model->position);
MulMatrix0(&light_mtx, &mtx, &lmtx);
gte_SetRotMatrix(&mtx);
gte_SetTransMatrix(&mtx);
gte_SetLightMatrix(&lmtx);
int frameNum = frameCounter % model->header->frameCount;
int vertOffs = frameNum * model->header->vertexCount;
short halfSkinWidth = model->halfSkinWidth;
@ -449,18 +461,8 @@ void drawStuff(int counter)
gte_SetBackColor(48, 48, 48); // Ambient light color
gte_SetColorMatrix(&color_mtx); // Light color and direction
MATRIX mtx, lmtx;
RotMatrix(&rot, &mtx);
TransMatrix(&mtx, &pos);
MulMatrix0(&light_mtx, &mtx, &lmtx);
gte_SetRotMatrix(&mtx);
gte_SetTransMatrix(&mtx);
gte_SetLightMatrix(&lmtx);
drawModel(&playerModel, &playerSkin, -40, counter >> 2);
//drawModel(&shamblerModel, &shamblerSkin, 80, counter >> 2);
drawModel(&shamblerModel, &shamblerSkin, 80, counter >> 2);
}
// Main function, program entrypoint

Loading…
Cancel
Save