Browse Source

Implemented triangle strip topology for drawing faces

tess_experiment
Nico de Poel 3 years ago
parent
commit
7606d89998
  1. 2
      main.c
  2. 2
      ps1bsp.h
  3. BIN
      test.ps1bsp
  4. 26
      world.c

2
main.c

@ -8,7 +8,7 @@
extern u_long tim_e1m1[];
extern u_long bsp_test[];
VECTOR cam_pos = { 2176, 1152, 128 }; // START
VECTOR cam_pos = { 2176, 1152, 272 }; // START
//VECTOR cam_pos = { 1920, -1408, 352 }; // E1M1
SVECTOR cam_rot = { 0, 0, 0 };

2
ps1bsp.h

@ -60,7 +60,7 @@ typedef struct
typedef struct
{
unsigned short firstFaceVertex;
unsigned short numFaceVertices;
unsigned char numFaceVertices;
} ps1bsp_face_t;
// Pre-parsed and encoded entity data (this runs the risk of becoming too bloated)

BIN
test.ps1bsp

26
world.c

@ -63,12 +63,28 @@ void world_draw(const world_t *world)
vecs[vertIdx].pad = vert->baseLight;
}
// Draw the face as a triangle fan
for (int vertIdx = 1; vertIdx < face->numFaceVertices - 1; ++vertIdx)
// Draw the face as a triangle strip
const SVECTOR *v0, *v1, *v2;
const SVECTOR *head = vecs;
const SVECTOR *tail = vecs + face->numFaceVertices;
u_char reverse = 0;
v2 = head++; // Initialize first vertex to index 0 and set head to index 1
for (u_char vertIdx = 0; vertIdx < face->numFaceVertices - 2; ++vertIdx)
{
const SVECTOR *v0 = &vecs[0];
const SVECTOR *v1 = &vecs[vertIdx];
const SVECTOR *v2 = &vecs[vertIdx + 1];
if (reverse ^= 1)
{
v0 = v2;
v1 = head;
v2 = --tail;
}
else
{
v0 = v1;
v1 = ++head;
v2 = tail;
}
// Naively draw the triangle with GTE, nothing special or optimized about this
gte_ldv3(v0, v1, v2);

Loading…
Cancel
Save