24namespace deluge::hid::display {
45 static constexpr float kZStep = 0.4f;
47 static constexpr float kFov = 3.14159265358979323846f;
91 [[nodiscard]] Projected
project(
size_t i)
const;
97 [[nodiscard]]
float depthOf(
size_t i)
const {
return stars_[i].z; }
122 std::array<Star, kNumStars> stars_{};
123 uint32_t rngState_{0xCAFE5678};
static constexpr float kMaxDepth
Stars respawn at this depth once they pass the viewer.
Definition starfield.h:43
uint32_t nextRandom()
Step the linear congruential generator.
Definition starfield.cpp:23
static constexpr float kCentreY
Projected screen centre, Y, in pixels: (OLED_MAIN_TOPMOST_PIXEL + OLED_MAIN_HEIGHT_PIXELS) / 2.
Definition starfield.h:51
Projected project(size_t i) const
Project a star onto the screen.
Definition starfield.cpp:57
void advance()
Advance every star one frame toward the viewer, respawning any that pass it.
Definition starfield.cpp:48
float nextRandomFloat()
Step the linear congruential generator, mapped to [0, 1).
Definition starfield.cpp:28
static constexpr float kMinDepth
Floor applied to z when projecting.
Definition starfield.h:62
static constexpr float kZStep
Depth consumed per frame.
Definition starfield.h:45
Starfield()
Construct a field that is already fully populated, so the first rendered frame is not empty.
Definition starfield.h:77
static constexpr float kFov
Field of view, radians.
Definition starfield.h:47
static constexpr float kCentreX
Projected screen centre, X, in pixels.
Definition starfield.h:49
static constexpr size_t kNumStars
Number of stars in the field.
Definition starfield.h:41
float depthOf(size_t i) const
Depth of a star. Exposed for tests.
Definition starfield.h:97
void scatter()
Re-scatter every star across the full depth range.
Definition starfield.cpp:40
static constexpr float kNearThreshold
Definition starfield.h:54
void respawn(Star &star, float z)
Give a star a fresh random x/y at the given depth.
Definition starfield.cpp:32
A star projected onto the screen.
Definition starfield.h:69
int32_t x
screen X, pixels
Definition starfield.h:70
int32_t y
screen Y, pixels
Definition starfield.h:71
int32_t size
1 or 2, in pixels square
Definition starfield.h:72
Definition starfield.h:100
float y
3D position, roughly -100 to +100
Definition starfield.h:102
float x
3D position, roughly -256 to +256
Definition starfield.h:101
float z
depth, positive, roughly up to kMaxDepth
Definition starfield.h:103