cyberspace-demo: Real first-person fly-through of the Net

Replace the spinning-cube placeholder with a proper System Shock
Cyberspace fly-through (shodan.fandom.com/wiki/Cyberspace):

- Camera dragged along a gently curving data-current spline with
  banking roll and weightless bob; look direction blended toward
  straight-ahead so the vanishing point stays centered
- Octagonal tunnel rings + longitudinal ribs with depth fade and
  near-plane segment clipping; radius swells between four named
  zones (military spur / research grotto / data cistern / security
  grid) via smoothstep blends
- Wiki-canon objects recycled around a 256-unit loop: data object
  (purple cube), data fragment (yellow square + orange diamonds),
  infonode signpost, security mine, integrity restorative, ICE
  pyramid growths, and SHODAN's diamond core with Bezier tentacles
  + rotating shield ring once per loop
- NetDeck-style HUD: 3x5 bitmap font, crosshair, LNK/TRACE meters,
  zone banners, DIST/VEL/NODE readouts; Space = freeze convention
- 3x3 view matrix built per frame from the path tangent; Bresenham
  lines against the direct framebuffer, dimc() depth fading

Verified: clean build (0 warnings), 240-frame smoke, 5000-frame
soak, frame dumps inspected at five flight points.
This commit is contained in:
Dejvino
2026-11-16 21:02:10 +01:00
parent 57d79ee296
commit cebfed96a8
2 changed files with 70 additions and 57 deletions
+57 -46
View File
@@ -1,53 +1,60 @@
# T-Deck Cyberspace Demo # T-Deck Cyberspace Demo
A wireframe 3D fly-through demo inspired by [System Shock's Cyberspace](https://shodan.fandom.com/wiki/Cyberspace) A first-person wireframe fly-through of Cyberspace, inspired by
from the Shodan Fandom wiki. Renders a rotating wireframe cube that appears to fly [System Shock's Cyberspace](https://shodan.fandom.com/wiki/Cyberspace)
through a tunnel, evoking the cyberspace aesthetic from the System Shock games. from the Shodan Fandom wiki. The camera is dragged along a "river of data"
through immense rooms of glowing wireframe, populated with the classic
Cyberspace objects — a vibe study for the NetDeck game's jack-in view.
## Overview ## Overview
This demo demonstrates a wireframe 3D rendering engine capable of: Everything renders as glowing wireframe on a 320x240 framebuffer, exactly
- Rotating cube geometry with X/Y/Z axis spin like the wiki describes: *"important programs manifest as floating geometric
- Perspective projection for depth perception shapes in immense rooms of glowing wireframe. Hallways between rooms
- Color-coded edges (SHODAN green for vertical, cyber teal for horizontal) represent rivers of data between nodes, which drag the user along in
- Pulsing central "SHODAN core" visual effect digital currents."*
The visual style draws from the System Shock cyberspace environment: a - **Data current** — the camera follows a gently curving spline path,
wireframe 3D space where the player moves weightlessly, collecting data banking into curves and bobbing weightlessly; the tunnel of octagonal
and facing SHODAN's security programs. rings swells between narrow hallways and vast rooms (zones) with
smoothstep radius blends.
- **Cyberspace objects** (per the wiki's Objects list), recycled around a
256-unit loop so the flight never ends:
| Object | Wiki appearance | In the demo |
|---|---|---|
| Data Object | spinning purple cube | two nested counter-rotating wireframe cubes |
| Data Fragment | yellow square + 4 orange diamonds | spinning square with octahedra on the diagonals |
| Infonode | geometric signpost | green pylon + octahedron head + orbiting spark |
| Security Mine | blue sphere | pulsing billboard circles + orange prime blink |
| Integrity Restorative | red cross | three-axis red wireframe cross |
| I.C.E. Barrier | geometric growths | cluster of magenta pyramids, shimmering |
| SHODAN's core | vertical diamond ending in four curved tentacles | Bézier tentacles + rotating shield ring, once per loop |
- **Void stars** — distant fixed points for orientation (rotation-only
parallax, translation-free, infinity-depth).
- **NetDeck-style HUD chrome** — crosshair, LNK/TRACE meters, zone banner
(MILITARY SPUR / RESEARCH GROTTO / DATA CISTERN / SECURITY GRID), DIST /
VEL / NODE readouts in a 3x5 bitmap font.
## Controls ## Controls
- Default: auto-rotating fly-through - **SPACE** — freeze / resume the current (NetDeck `Space` freeze convention)
- Press **SPACE** to toggle between auto-spin and manual rotation - **f / s** — faster / slower current
- Press **ESCAPE** or **Q** to quit - **h** — toggle HUD
- **ESC** — quit
## Building & Running ## Building & Running
```bash ```bash
# Build and run the cyberflythrough demo # Build and run the cyberflythrough demo
make run
# Build with different APP name
make run APP=Cyberflythrough make run APP=Cyberflythrough
# Headless smoke test (240 frames, dump BMP) # Headless smoke test (240 frames, dump BMP)
make smoke make smoke APP=Cyberflythrough
# Clean built binary # Clean built binary
make clean make clean
``` ```
## Key Features
| Feature | Description |
|---------|-------------|
| **Wireframe cube** | 8 vertices, 12 edges rotating in 3D |
| **Perspective projection** | Objects get smaller with "depth" |
| **SHODAN aesthetic** | Green vertical edges, teal horizontal edges |
| **Pulsing core** | Central green eye pulses rhythmically |
| **320x240 resolution** | Optimized for T-Deck screen |
## File Structure ## File Structure
``` ```
@@ -59,29 +66,33 @@ cyberspace-demo/
│ └── main.cpp # SDL3 host loop — window, framebuffer, setup()/loop() │ └── main.cpp # SDL3 host loop — window, framebuffer, setup()/loop()
└── examples/ └── examples/
└── Cyberflythrough/ └── Cyberflythrough/
└── Cyberflythrough.cpp # Wireframe 3D demo sketch └── Cyberflythrough.cpp # Cyberspace fly-through sketch
``` ```
## How It Works ## How It Works
The sketch implements the standard emulator contract: The sketch implements the standard emulator contract:
- `setup()` — called once at launch, initializes rotation angles - `setup()` — called once at launch, seeds the object/streak/star fields
- `loop()` — called once per frame (~60 fps) - `loop()` — called once per frame (~60 fps)
- Clears framebuffer to black - consumes keys from `emu::keyboard` (freeze, speed, HUD)
- Increments rotation angles for continuous spin - advances the camera along the data-current spline (`pathX/pathY`),
- Projects 8 cube vertices through rotation + perspective banks the roll into curves, simulates streaks and object recycling
- Draws all 12 cube edges using Bresenham's line algorithm - transforms world → view space with one 3x3 matrix per frame
- Draws a pulsing "SHODAN core" in the center (yaw/pitch from the path tangent, blended toward straight-ahead) and
- Sets `emuGfx::dirty = true` to present the frame perspective-projects
- draws octagonal tunnel rings + longitudinal ribs with depth fade,
near-plane segment clipping, and the object wireframes
- draws HUD chrome and sets `emuGfx::dirty = true`
The wireframe rendering uses fixed-function transformation: Geometry notes:
1. Rotate vertices around X, Y, and Z axes - All lines are Bresenham's algorithm against the direct framebuffer.
2. Project 3D coordinates to 2D using perspective division - Depth fade multiplies each color by a per-segment brightness using
3. Draw connecting edges between cube vertices `dimc()`, giving the glowing-wireframe-into-the-distance look without
a z-buffer.
- Segments are clipped against the near plane in view space so objects
sweeping past the camera don't smear across the screen.
Edge colors are differentiated: vertical edges (connecting front/back faces) Potential next steps toward NetDeck integration: replace the scripted
are rendered in SHODAN green (0xFF00FF00), while horizontal edges are camera with trackball-steered flight, pin the tunnel zones to actual
cyber teal (0xFF00AAFF), helping convey the 3D structure. network nodes (AIRLK/JUNC/HIVE), and let data-object pickups arm the
daemon keys (`1` FRENZY.EXE / `2` BLIND).
The central "eye" effect is a pulsing circle that rhythmically expands
and contracts, evoking SHODAN's omnipresent observation within cyberspace.
@@ -199,10 +199,11 @@ static void drawBar(int x, int y, int w, int hgt, float frac, uint32_t c)
// Camera + data-current path // Camera + data-current path
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// The current flows along +Z; its center drifts like a slow river. // The current flows along +Z; its center drifts like a slow river.
static float pathX(float z) { return 6.0f * sinf(z * 0.045f) + 3.0f * sinf(z * 0.013f + 1.7f); } // (Gentle amplitudes + long wavelengths: rivers drag, they don't whip.)
static float pathY(float z) { return 4.0f * sinf(z * 0.031f + 4.0f) + 2.0f * sinf(z * 0.08f); } static float pathX(float z) { return 3.5f * sinf(z * 0.020f) + 1.5f * sinf(z * 0.008f + 1.7f); }
static float pathXdz(float z) { return 6.0f * 0.045f * cosf(z * 0.045f) + 3.0f * 0.013f * cosf(z * 0.013f + 1.7f); } static float pathY(float z) { return 2.0f * sinf(z * 0.015f + 4.0f) + 1.2f * sinf(z * 0.05f); }
static float pathYdz(float z) { return 4.0f * 0.031f * cosf(z * 0.031f + 4.0f) + 2.0f * 0.08f * cosf(z * 0.08f); } static float pathXdz(float z) { return 3.5f * 0.020f * cosf(z * 0.020f) + 1.5f * 0.008f * cosf(z * 0.008f + 1.7f); }
static float pathYdz(float z) { return 2.0f * 0.015f * cosf(z * 0.015f + 4.0f) + 1.2f * 0.05f * cosf(z * 0.05f); }
// Zones: alternate narrow hallways and immense rooms (wiki: "immense rooms // Zones: alternate narrow hallways and immense rooms (wiki: "immense rooms
// of glowing wireframe" connected by rivers of data). // of glowing wireframe" connected by rivers of data).
@@ -257,11 +258,13 @@ static void buildView()
camY = pathY(camDist) + 0.3f * sinf(tGlobal * 0.9f); // weightless bob camY = pathY(camDist) + 0.3f * sinf(tGlobal * 0.9f); // weightless bob
camZ = camDist; camZ = camDist;
// Orientation follows the current's tangent (+z dominant). // Orientation mostly follows the current's tangent, but blended toward
float fx = pathXdz(camDist), fy = pathYdz(camDist); // straight +Z so the vanishing point stays near screen center.
float yaw = atan2f(fx, 1.0f); float tx = pathXdz(camDist), ty = pathYdz(camDist);
float n = sqrtf(fx * fx + 1.0f); const float STEER = 0.55f; // 0 = straight ahead, 1 = follow tangent fully
float pitch = atan2f(fy, n); float yaw = atan2f(tx * STEER, 1.0f);
float n = sqrtf(tx * STEER * tx * STEER + 1.0f);
float pitch = atan2f(ty * STEER, n);
// Bank into curves, like drifting weightlessly through the current. // Bank into curves, like drifting weightlessly through the current.
static float prevYaw = 0.0f; static float prevYaw = 0.0f;
@@ -545,7 +548,7 @@ static void drawObjInfonode(float cx, float cy, float cz, float s, float spin)
} }
// Security Mine: blue sphere (billboard circles, pulsing) // Security Mine: blue sphere (billboard circles, pulsing)
static void drawObjMine(float cx, float cy, float cz, float s, float vx, float vy, float vz) static void drawObjMine(float cx, float, float, float s, float vx, float vy, float vz)
{ {
float pulse = 1.0f + 0.15f * sinf(tGlobal * 3.0f + cx); float pulse = 1.0f + 0.15f * sinf(tGlobal * 3.0f + cx);
int fade = (int)(256.0f * (1.0f - 0.85f * vz / FARZ)); int fade = (int)(256.0f * (1.0f - 0.85f * vz / FARZ));
@@ -585,7 +588,6 @@ static void drawShodan(float wx, float wy, float wz)
float pulse = 0.65f + 0.35f * sinf(tGlobal * 2.4f); float pulse = 0.65f + 0.35f * sinf(tGlobal * 2.4f);
int bright = (int)(150 + 106 * pulse); int bright = (int)(150 + 106 * pulse);
float rot = tGlobal * 0.35f; float rot = tGlobal * 0.35f;
float c = cosf(rot), si = sinf(rot);
// rotate ring/tentacle anchor points around Y // rotate ring/tentacle anchor points around Y
const int NR = 8; const int NR = 8;