|
|
@ -410,26 +410,24 @@ void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameC |
|
|
gte_SetRotMatrix(&model_mtx); |
|
|
gte_SetRotMatrix(&model_mtx); |
|
|
gte_SetTransMatrix(&model_mtx); |
|
|
gte_SetTransMatrix(&model_mtx); |
|
|
|
|
|
|
|
|
ps1mdl_vertex_t *vin = baseVertex; |
|
|
|
|
|
for (unsigned short vertIdx = 0; vertIdx < vertexCount; ++vertIdx, ++vin) |
|
|
|
|
|
|
|
|
// Scale, translate and convert vertex data to SVECTOR ahead of time for all vertices. |
|
|
|
|
|
// This eliminates duplicate calculations on vertices shared by multiple triangles. |
|
|
|
|
|
SVECTOR *v = vertexBuffer; |
|
|
|
|
|
for (unsigned short vertIdx = 0; vertIdx < vertexCount; ++vertIdx, ++baseVertex, ++v) |
|
|
{ |
|
|
{ |
|
|
SVECTOR *v = &vertexBuffer[vertIdx]; |
|
|
|
|
|
setVector(v, SCTR(vin,0), SCTR(vin,1), SCTR(vin,2)); |
|
|
|
|
|
|
|
|
setVector(v, SCTR(baseVertex,0), SCTR(baseVertex,1), SCTR(baseVertex,2)); |
|
|
|
|
|
v->pad = baseVertex->normalIndex; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
for (unsigned short triIdx = 0; triIdx < triangleCount; ++triIdx) |
|
|
for (unsigned short triIdx = 0; triIdx < triangleCount; ++triIdx) |
|
|
{ |
|
|
{ |
|
|
ps1mdl_triangle_t *tri = &model->triangles[triIdx]; |
|
|
ps1mdl_triangle_t *tri = &model->triangles[triIdx]; |
|
|
|
|
|
|
|
|
ps1mdl_vertex_t *v0 = &baseVertex[tri->vertexIndex[0]]; |
|
|
|
|
|
ps1mdl_vertex_t *v1 = &baseVertex[tri->vertexIndex[1]]; |
|
|
|
|
|
ps1mdl_vertex_t *v2 = &baseVertex[tri->vertexIndex[2]]; |
|
|
|
|
|
|
|
|
SVECTOR *v0 = &vertexBuffer[tri->vertexIndex[0]]; |
|
|
|
|
|
SVECTOR *v1 = &vertexBuffer[tri->vertexIndex[1]]; |
|
|
|
|
|
SVECTOR *v2 = &vertexBuffer[tri->vertexIndex[2]]; |
|
|
|
|
|
|
|
|
SVECTOR *pos0 = &vertexBuffer[tri->vertexIndex[0]]; |
|
|
|
|
|
SVECTOR *pos1 = &vertexBuffer[tri->vertexIndex[1]]; |
|
|
|
|
|
SVECTOR *pos2 = &vertexBuffer[tri->vertexIndex[2]]; |
|
|
|
|
|
|
|
|
|
|
|
gte_ldv3(pos0, pos1, pos2); |
|
|
|
|
|
|
|
|
gte_ldv3(v0, v1, v2); |
|
|
gte_rtpt(); // Rotation, Translation and Perspective triplet (all three vertices at once) |
|
|
gte_rtpt(); // Rotation, Translation and Perspective triplet (all three vertices at once) |
|
|
|
|
|
|
|
|
// Normal clipping for backface culling |
|
|
// Normal clipping for backface culling |
|
|
@ -480,7 +478,7 @@ void drawModel(MATRIX *view_matrix, ps1mdl_t *model, ps1skin_t *skin, int frameC |
|
|
// Calculate vertex color based on normal |
|
|
// Calculate vertex color based on normal |
|
|
// TODO: we could probably speed this up by precalculating the lighting for each normal, if we need to draw more than 162 vertices |
|
|
// TODO: we could probably speed this up by precalculating the lighting for each normal, if we need to draw more than 162 vertices |
|
|
gte_ldrgb(&poly->r0); |
|
|
gte_ldrgb(&poly->r0); |
|
|
gte_ldv3(anorms[v0->normalIndex], anorms[v1->normalIndex], anorms[v2->normalIndex]); |
|
|
|
|
|
|
|
|
gte_ldv3(anorms[v0->pad], anorms[v1->pad], anorms[v2->pad]); |
|
|
gte_nct(); |
|
|
gte_nct(); |
|
|
gte_strgb3(&poly->r0, &poly->r1, &poly->r2); |
|
|
gte_strgb3(&poly->r0, &poly->r1, &poly->r2); |
|
|
|
|
|
|
|
|
|