![]() |
Deluge Firmware 1.3.0
Build date: 2026.08.23
|
Perspective-projection starfield. More...
#include <starfield.h>
Classes | |
| struct | Projected |
| A star projected onto the screen. More... | |
| struct | Star |
Public Member Functions | |
| Starfield () | |
| Construct a field that is already fully populated, so the first rendered frame is not empty. | |
| void | scatter () |
| Re-scatter every star across the full depth range. | |
| void | advance () |
| Advance every star one frame toward the viewer, respawning any that pass it. | |
| Projected | project (size_t i) const |
| Project a star onto the screen. | |
| float | depthOf (size_t i) const |
| Depth of a star. Exposed for tests. | |
Static Public Attributes | |
Field geometry | |
| static constexpr size_t | kNumStars = 60 |
| Number of stars in the field. | |
| static constexpr float | kMaxDepth = 32.0f |
| Stars respawn at this depth once they pass the viewer. | |
| static constexpr float | kZStep = 0.4f |
| Depth consumed per frame. | |
| static constexpr float | kFov = 3.14159265358979323846f |
| Field of view, radians. | |
| static constexpr float | kCentreX = 64.0f |
| Projected screen centre, X, in pixels. | |
| static constexpr float | kCentreY = 26.0f |
| Projected screen centre, Y, in pixels: (OLED_MAIN_TOPMOST_PIXEL + OLED_MAIN_HEIGHT_PIXELS) / 2. | |
| static constexpr float | kNearThreshold = kMaxDepth * 0.4f |
| static constexpr float | kMinDepth = 0.01f |
| Floor applied to z when projecting. | |
Private Member Functions | |
| uint32_t | nextRandom () |
| Step the linear congruential generator. | |
| float | nextRandomFloat () |
| Step the linear congruential generator, mapped to [0, 1). | |
| void | respawn (Star &star, float z) |
| Give a star a fresh random x/y at the given depth. | |
Private Attributes | |
| std::array< Star, kNumStars > | stars_ {} |
| uint32_t | rngState_ {0xCAFE5678} |
Perspective-projection starfield.
Stars hold a 3D position and are projected with factor = kFov / z, so they appear to fly toward the viewer as z decrements.
|
inlinenodiscard |
Depth of a star. Exposed for tests.
| i | Star index, less than kNumStars. |
|
private |
Step the linear congruential generator.
|
private |
Step the linear congruential generator, mapped to [0, 1).
|
nodiscard |
Project a star onto the screen.
| i | Star index, less than kNumStars. |
|
private |
Give a star a fresh random x/y at the given depth.
| star | The star to overwrite. |
| z | Depth to place it at. |
| void deluge::hid::display::Starfield::scatter | ( | ) |
Re-scatter every star across the full depth range.
|
staticconstexpr |
Floor applied to z when projecting.
The reference implementation relies on Rust's saturating f32 as i32. A C++ static_cast of an out-of-range float is undefined behaviour, and z can land arbitrarily close to zero, so the projection factor is bounded instead.
|
staticconstexpr |
Depth threshold: stars nearer than this (same depth units as kMaxDepth) draw as 2x2 blocks rather than single pixels.