|
|
|
@ -270,21 +270,38 @@ static void world_drawnode(const world_t *world, short nodeIdx, char *scratchpt |
|
|
|
const ps1bsp_node_t *node = &world->nodes[nodeIdx]; |
|
|
|
|
|
|
|
// Still not sure why we have faces attached to nodes... Try to remove this and see what happens |
|
|
|
ps1bsp_face_t *face = &world->faces[node->firstFace]; |
|
|
|
for (u_short faceIdx = 0; faceIdx < node->numFaces; ++faceIdx, ++face) |
|
|
|
{ |
|
|
|
// Check if we've already drawn this face on the current frame |
|
|
|
if (face->drawFrame == frameNum) |
|
|
|
continue; |
|
|
|
|
|
|
|
world_drawface(world, face, scratchptr); |
|
|
|
face->drawFrame = frameNum; |
|
|
|
} |
|
|
|
// ps1bsp_face_t *face = &world->faces[node->firstFace]; |
|
|
|
// for (u_short faceIdx = 0; faceIdx < node->numFaces; ++faceIdx, ++face) |
|
|
|
// { |
|
|
|
// // Check if we've already drawn this face on the current frame |
|
|
|
// if (face->drawFrame == frameNum) |
|
|
|
// continue; |
|
|
|
|
|
|
|
// world_drawface(world, face, scratchptr); |
|
|
|
// face->drawFrame = frameNum; |
|
|
|
// } |
|
|
|
|
|
|
|
world_drawnode(world, node->front, scratchptr); |
|
|
|
world_drawnode(world, node->back, scratchptr); |
|
|
|
} |
|
|
|
|
|
|
|
static u_short world_leafAtPoint(const world_t *world, const VECTOR *point) |
|
|
|
{ |
|
|
|
short nodeIdx = 0; |
|
|
|
while (nodeIdx >= 0) |
|
|
|
{ |
|
|
|
const ps1bsp_node_t *node = &world->nodes[nodeIdx]; |
|
|
|
const ps1bsp_plane_t *plane = &world->planes[node->planeId]; |
|
|
|
|
|
|
|
// TODO: can be optimized for axis-aligned planes, no need for a dot product there |
|
|
|
short dist = m_pointPlaneDist4(point, &plane->normal, plane->dist); |
|
|
|
|
|
|
|
nodeIdx = dist < 0 ? node->back : node->front; // TODO: this can be done branchless with (dist < 0)^1 |
|
|
|
} |
|
|
|
|
|
|
|
return ~nodeIdx; |
|
|
|
} |
|
|
|
|
|
|
|
void world_draw(const world_t *world) |
|
|
|
{ |
|
|
|
int p; |
|
|
|
@ -293,5 +310,7 @@ void world_draw(const world_t *world) |
|
|
|
gte_SetRotMatrix(&vp_matrix); |
|
|
|
gte_SetTransMatrix(&vp_matrix); |
|
|
|
|
|
|
|
cam_leaf = world_leafAtPoint(world, &cam_pos); |
|
|
|
|
|
|
|
world_drawnode(world, 0, scratchpad); |
|
|
|
} |