From cebfed96a8aaf50bfd704a2c787c0e7369a627e5 Mon Sep 17 00:00:00 2001 From: Dejvino Date: Mon, 16 Nov 2026 21:02:10 +0100 Subject: [PATCH] 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. --- cyberspace-demo/README.md | 103 ++++++++++-------- .../Cyberflythrough/Cyberflythrough.cpp | 24 ++-- 2 files changed, 70 insertions(+), 57 deletions(-) diff --git a/cyberspace-demo/README.md b/cyberspace-demo/README.md index b4c8ad8..7707e1c 100644 --- a/cyberspace-demo/README.md +++ b/cyberspace-demo/README.md @@ -1,53 +1,60 @@ # T-Deck Cyberspace Demo -A wireframe 3D fly-through demo inspired by [System Shock's Cyberspace](https://shodan.fandom.com/wiki/Cyberspace) -from the Shodan Fandom wiki. Renders a rotating wireframe cube that appears to fly -through a tunnel, evoking the cyberspace aesthetic from the System Shock games. +A first-person wireframe fly-through of Cyberspace, inspired by +[System Shock's Cyberspace](https://shodan.fandom.com/wiki/Cyberspace) +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 -This demo demonstrates a wireframe 3D rendering engine capable of: -- Rotating cube geometry with X/Y/Z axis spin -- Perspective projection for depth perception -- Color-coded edges (SHODAN green for vertical, cyber teal for horizontal) -- Pulsing central "SHODAN core" visual effect +Everything renders as glowing wireframe on a 320x240 framebuffer, exactly +like the wiki describes: *"important programs manifest as floating geometric +shapes in immense rooms of glowing wireframe. Hallways between rooms +represent rivers of data between nodes, which drag the user along in +digital currents."* -The visual style draws from the System Shock cyberspace environment: a -wireframe 3D space where the player moves weightlessly, collecting data -and facing SHODAN's security programs. +- **Data current** — the camera follows a gently curving spline path, + banking into curves and bobbing weightlessly; the tunnel of octagonal + 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 -- Default: auto-rotating fly-through -- Press **SPACE** to toggle between auto-spin and manual rotation -- Press **ESCAPE** or **Q** to quit +- **SPACE** — freeze / resume the current (NetDeck `Space` freeze convention) +- **f / s** — faster / slower current +- **h** — toggle HUD +- **ESC** — quit ## Building & Running ```bash # Build and run the cyberflythrough demo -make run - -# Build with different APP name make run APP=Cyberflythrough # Headless smoke test (240 frames, dump BMP) -make smoke +make smoke APP=Cyberflythrough # Clean built binary 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 ``` @@ -59,29 +66,33 @@ cyberspace-demo/ │ └── main.cpp # SDL3 host loop — window, framebuffer, setup()/loop() └── examples/ └── Cyberflythrough/ - └── Cyberflythrough.cpp # Wireframe 3D demo sketch + └── Cyberflythrough.cpp # Cyberspace fly-through sketch ``` ## How It Works 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) - - Clears framebuffer to black - - Increments rotation angles for continuous spin - - Projects 8 cube vertices through rotation + perspective - - Draws all 12 cube edges using Bresenham's line algorithm - - Draws a pulsing "SHODAN core" in the center - - Sets `emuGfx::dirty = true` to present the frame + - consumes keys from `emu::keyboard` (freeze, speed, HUD) + - advances the camera along the data-current spline (`pathX/pathY`), + banks the roll into curves, simulates streaks and object recycling + - transforms world → view space with one 3x3 matrix per frame + (yaw/pitch from the path tangent, blended toward straight-ahead) and + 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: -1. Rotate vertices around X, Y, and Z axes -2. Project 3D coordinates to 2D using perspective division -3. Draw connecting edges between cube vertices +Geometry notes: +- All lines are Bresenham's algorithm against the direct framebuffer. +- Depth fade multiplies each color by a per-segment brightness using + `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) -are rendered in SHODAN green (0xFF00FF00), while horizontal edges are -cyber teal (0xFF00AAFF), helping convey the 3D structure. - -The central "eye" effect is a pulsing circle that rhythmically expands -and contracts, evoking SHODAN's omnipresent observation within cyberspace. \ No newline at end of file +Potential next steps toward NetDeck integration: replace the scripted +camera with trackball-steered flight, pin the tunnel zones to actual +network nodes (AIRLK/JUNC/HIVE), and let data-object pickups arm the +daemon keys (`1` FRENZY.EXE / `2` BLIND). diff --git a/cyberspace-demo/examples/Cyberflythrough/Cyberflythrough.cpp b/cyberspace-demo/examples/Cyberflythrough/Cyberflythrough.cpp index 8c5b891..4bc9271 100644 --- a/cyberspace-demo/examples/Cyberflythrough/Cyberflythrough.cpp +++ b/cyberspace-demo/examples/Cyberflythrough/Cyberflythrough.cpp @@ -199,10 +199,11 @@ static void drawBar(int x, int y, int w, int hgt, float frac, uint32_t c) // Camera + data-current path // --------------------------------------------------------------------------- // 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); } -static float pathY(float z) { return 4.0f * sinf(z * 0.031f + 4.0f) + 2.0f * sinf(z * 0.08f); } -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 pathYdz(float z) { return 4.0f * 0.031f * cosf(z * 0.031f + 4.0f) + 2.0f * 0.08f * cosf(z * 0.08f); } +// (Gentle amplitudes + long wavelengths: rivers drag, they don't whip.) +static float pathX(float z) { return 3.5f * sinf(z * 0.020f) + 1.5f * sinf(z * 0.008f + 1.7f); } +static float pathY(float z) { return 2.0f * sinf(z * 0.015f + 4.0f) + 1.2f * sinf(z * 0.05f); } +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 // 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 camZ = camDist; - // Orientation follows the current's tangent (+z dominant). - float fx = pathXdz(camDist), fy = pathYdz(camDist); - float yaw = atan2f(fx, 1.0f); - float n = sqrtf(fx * fx + 1.0f); - float pitch = atan2f(fy, n); + // Orientation mostly follows the current's tangent, but blended toward + // straight +Z so the vanishing point stays near screen center. + float tx = pathXdz(camDist), ty = pathYdz(camDist); + const float STEER = 0.55f; // 0 = straight ahead, 1 = follow tangent fully + 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. 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) -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); 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); int bright = (int)(150 + 106 * pulse); float rot = tGlobal * 0.35f; - float c = cosf(rot), si = sinf(rot); // rotate ring/tentacle anchor points around Y const int NR = 8;