|
|
@ -31,8 +31,8 @@ void world_load(const u_long *data, world_t *world) |
|
|
world->vertices = (ps1bsp_vertex_t*)bytes; |
|
|
world->vertices = (ps1bsp_vertex_t*)bytes; |
|
|
bytes += sizeof(ps1bsp_vertex_t) * world->header->numVertices; |
|
|
bytes += sizeof(ps1bsp_vertex_t) * world->header->numVertices; |
|
|
|
|
|
|
|
|
world->faceVertIndices = (unsigned short*)bytes; |
|
|
|
|
|
bytes += sizeof(unsigned short) * world->header->numFaceVertIndices; |
|
|
|
|
|
|
|
|
world->faceVertices = (ps1bsp_facevertex_t*)bytes; |
|
|
|
|
|
bytes += sizeof(ps1bsp_facevertex_t) * world->header->numFaceVertices; |
|
|
|
|
|
|
|
|
world->faces = (ps1bsp_face_t*)bytes; |
|
|
world->faces = (ps1bsp_face_t*)bytes; |
|
|
bytes += sizeof(ps1bsp_face_t) * world->header->numFaces; |
|
|
bytes += sizeof(ps1bsp_face_t) * world->header->numFaces; |
|
|
@ -52,19 +52,19 @@ void world_draw(const world_t *world) |
|
|
const CVECTOR *col = &colors[faceIdx % numColors]; |
|
|
const CVECTOR *col = &colors[faceIdx % numColors]; |
|
|
|
|
|
|
|
|
char *scratch = scratchpad; |
|
|
char *scratch = scratchpad; |
|
|
SVECTOR *vecs = (SVECTOR*)mem_scratch(&scratch, sizeof(SVECTOR) * face->numVertices); |
|
|
|
|
|
|
|
|
SVECTOR *vecs = (SVECTOR*)mem_scratch(&scratch, sizeof(SVECTOR) * face->numFaceVertices); |
|
|
|
|
|
|
|
|
// Copy this face's vertices into scratch RAM for fast reuse |
|
|
// Copy this face's vertices into scratch RAM for fast reuse |
|
|
unsigned short *faceVertIndex = &world->faceVertIndices[face->firstVertexIndex]; |
|
|
|
|
|
for (int vertIdx = 0; vertIdx < face->numVertices; ++vertIdx, ++faceVertIndex) |
|
|
|
|
|
|
|
|
ps1bsp_facevertex_t *faceVertex = &world->faceVertices[face->firstFaceVertex]; |
|
|
|
|
|
for (int vertIdx = 0; vertIdx < face->numFaceVertices; ++vertIdx, ++faceVertex) |
|
|
{ |
|
|
{ |
|
|
const ps1bsp_vertex_t *vert = &world->vertices[*faceVertIndex]; |
|
|
|
|
|
|
|
|
const ps1bsp_vertex_t *vert = &world->vertices[faceVertex->index]; |
|
|
vecs[vertIdx] = *((SVECTOR*)vert); |
|
|
vecs[vertIdx] = *((SVECTOR*)vert); |
|
|
vecs[vertIdx].pad = vert->baseLight; |
|
|
vecs[vertIdx].pad = vert->baseLight; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// Draw the face as a triangle fan |
|
|
// Draw the face as a triangle fan |
|
|
for (int vertIdx = 1; vertIdx < face->numVertices - 1; ++vertIdx) |
|
|
|
|
|
|
|
|
for (int vertIdx = 1; vertIdx < face->numFaceVertices - 1; ++vertIdx) |
|
|
{ |
|
|
{ |
|
|
const SVECTOR *v0 = &vecs[0]; |
|
|
const SVECTOR *v0 = &vecs[0]; |
|
|
const SVECTOR *v1 = &vecs[vertIdx]; |
|
|
const SVECTOR *v1 = &vecs[vertIdx]; |
|
|
@ -74,7 +74,7 @@ void world_draw(const world_t *world) |
|
|
gte_ldv3(v0, v1, v2); |
|
|
gte_ldv3(v0, v1, v2); |
|
|
gte_rtpt(); // Rotation, translation, perspective projection |
|
|
gte_rtpt(); // Rotation, translation, perspective projection |
|
|
|
|
|
|
|
|
// Normal clipping for backface culling |
|
|
|
|
|
|
|
|
// Normal clipping for backface culling (TODO: should be necessary only once per face, using plane normal & camera direction) |
|
|
gte_nclip(); |
|
|
gte_nclip(); |
|
|
gte_stopz(&p); |
|
|
gte_stopz(&p); |
|
|
if (p < 0) |
|
|
if (p < 0) |
|
|
|