Browse Source

Added plane and center point to face struct, for early backface culling.

master
Nico de Poel 3 years ago
parent
commit
eb548d13d8
  1. 23
      main.cpp
  2. 5
      ps1bsp.h

23
main.cpp

@ -280,6 +280,16 @@ static SVECTOR convertNormal(vec3_t normal)
return outNormal; return outNormal;
} }
static SVECTOR convertPoint(vec3_t point)
{
SVECTOR outPoint;
outPoint.vx = (short)(point.x * 4);
outPoint.vy = (short)(point.y * 4);
outPoint.vz = (short)(point.z * 4);
outPoint.pad = 1;
return outPoint;
}
int process_faces(const world_t* world) int process_faces(const world_t* world)
{ {
// Write some data to a file // Write some data to a file
@ -324,8 +334,12 @@ int process_faces(const world_t* world)
face_t* face = &world->faces[faceIdx]; face_t* face = &world->faces[faceIdx];
ps1bsp_face_t outFace = { 0 }; ps1bsp_face_t outFace = { 0 };
outFace.planeId = face->plane_id;
outFace.side = face->side;
outFace.firstFaceVertex = (unsigned short)outFaceVertices.size(); outFace.firstFaceVertex = (unsigned short)outFaceVertices.size();
Vec3 vertexSum;
// Traverse the list of face edges to collect all of the face's vertices // Traverse the list of face edges to collect all of the face's vertices
BoundBox bounds; BoundBox bounds;
for (int edgeListIdx = 0; edgeListIdx < face->ledge_num; ++edgeListIdx) for (int edgeListIdx = 0; edgeListIdx < face->ledge_num; ++edgeListIdx)
@ -343,10 +357,14 @@ int process_faces(const world_t* world)
// Calculate bounding box of this face // Calculate bounding box of this face
const vertex_t* vertex = &world->vertices[vertIndex]; const vertex_t* vertex = &world->vertices[vertIndex];
Vec3 vertexPoint = vertex->toVec();
if (edgeListIdx == 0) if (edgeListIdx == 0)
bounds.init(vertex->toVec());
bounds.init(vertexPoint);
else else
bounds.includePoint(vertex->toVec());
bounds.includePoint(vertexPoint);
// Sum all vertices to calculate an average center point
vertexSum = vertexSum + vertexPoint;
} }
// Sample lightmap contribution of this face on each vertex // Sample lightmap contribution of this face on each vertex
@ -369,6 +387,7 @@ int process_faces(const world_t* world)
// export_lightmap(world, face, bounds, faceIdx); // export_lightmap(world, face, bounds, faceIdx);
outFace.numFaceVertices = (unsigned short)(outFaceVertices.size() - outFace.firstFaceVertex); outFace.numFaceVertices = (unsigned short)(outFaceVertices.size() - outFace.firstFaceVertex);
outFace.centerPoint = convertPoint(vertexSum / outFace.numFaceVertices);
outFaces.push_back(outFace); outFaces.push_back(outFace);
} }

5
ps1bsp.h

@ -71,9 +71,14 @@ typedef struct
typedef struct typedef struct
{ {
unsigned short planeId;
unsigned short side;
unsigned short firstFaceVertex; unsigned short firstFaceVertex;
unsigned short numFaceVertices; unsigned short numFaceVertices;
SVECTOR centerPoint;
u_long drawFrame; // Which frame was this face last drawn on? Used to check if this face should be drawn. u_long drawFrame; // Which frame was this face last drawn on? Used to check if this face should be drawn.
} ps1bsp_face_t; } ps1bsp_face_t;

Loading…
Cancel
Save