| PSHOT-ENG — Build Your Own 3D Engine in ISO C89 | Contents | Chapter 02 | Going Further |
With Chapter 06 complete, pshot is a portable, playable 3D software engine. Here are the next architectural milestones that bridge the gap from a grid dungeon to full Quake / Quake 2 visuals—ordered from most approachable to most ambitious, with concepts to look up and hints rather than pre-baked solutions.
Not everything needs a 3D mesh. Classic shooters render pickups, torches, and explosions as camera-facing quads (billboards). Transform the sprite’s center point into view space, offset left/right by ±half_w and up/down by ±half_h directly in view space, and rasterize with a transparent color key (such as magenta 0x00FF00FF) skipped before writing to the framebuffer or Z-buffer.
Concepts to look up: view-space billboarding, chroma-key transparency, alpha testing.
To shoot targets, cast a 3D ray from player.pos along the camera forward vector (sin(yaw)*cos(pitch), sin(pitch), cos(yaw)*cos(pitch)). Step through the map grid using Amanatides & Woo’s fast voxel DDA traversal, and test ray-sphere or ray-AABB intersections against active entities. Draw your weapon overlay last in screen space, skipping transparent pixels.
Concepts to look up: 3D DDA grid traversal, slab method ray-AABB intersection.
Quake 1 and 2 look rich even with low-res textures because lighting is stored separately from wall art. Give each wall surface a tiny secondary 16x16 brightness grid computed offline (or at level load) by tracing shadow rays to point lights. During rasterization, sample the texture pixel and multiply by the bilinearly interpolated lightmap intensity—or bake both into a Quake-style surface cache once per visible face.
Concepts to look up: Quake surface caching, luxels, bilinear filtering.
Our Chapter 05 grid works great for right-angle corridors, but arbitrary sloped ramps, bridges, and outdoor courtyards need a spatial tree. A Binary Space Partitioning (BSP) tree recursively splits world polygons along planes into convex leaf rooms. Walking the tree front-to-back lets you reject entire unseen rooms via portal frustums or precomputed PVS bitsets.
Concepts to look up: Binary Space Partitioning, solid-leaf BSP collision, portal culling, PVS bitvectors.
Quake 2’s .md2 binary format is famously simple to parse in pure C89: a fixed header, a list of triangles, UV coordinates, and compressed vertex frames. Smooth animation is just linear interpolation between frame A and frame B: v = vA + (vB - vA) * frac, fed straight into rast_tri_tex.
Concepts to look up: Quake 2 MD2 specification, vertex keyframe lerp.
If you want pshot to fly at 60 FPS on a 1995 Pentium 100 or 486DX4 without relying on heavy FPU divides, replace per-pixel floating-point barycentrics with a horizontal scanline rasterizer using s32 16.16 fixed-point steppers and Quake’s 16-pixel perspective subdivision.
Concepts to look up: 16.16 fixed-point arithmetic, scanline edge tables, active edge lists, Quake span subdivision.
| « Ch 06: Audio & Win32 Builds | Table of Contents | Contents » |