MXVK Vulkan Framework 0.24.0
C++20 Vulkan rendering framework for practical 2D and 3D application development with SDL3.
Loading...
Searching...
No Matches
starfield.hpp
Go to the documentation of this file.
1#ifndef ASTEROIDS3D_STARFIELD_HPP
2#define ASTEROIDS3D_STARFIELD_HPP
3
4/**
5 * @file starfield.hpp
6 * @brief Animated starfield used by the Asteroids scene.
7 */
8
10
11namespace mxvk {
12 class VK_Sprite3D;
13 class VK_Window;
14} // namespace mxvk
15
16namespace space {
17
18 /**
19 * @class StarField
20 * @brief Manages and renders a camera-centered field of animated stars.
21 */
22 class StarField {
23 public:
24 /** @brief Creates an uninitialized starfield. */
25 StarField() = default;
26
27 /**
28 * @brief Creates the stars.
29 * @param star_count Number of stars.
30 * @param min_radius Inner spawn radius.
31 * @param max_radius Outer spawn radius.
32 */
33 void init(int star_count, float min_radius, float max_radius);
34 /**
35 * @brief Assigns the non-owning sprite batch used to render stars.
36 * @param sprite_batch Sprite batch, which must outlive this object.
37 */
38 void setSprite(mxvk::VK_Sprite3D *sprite_batch);
39 /**
40 * @brief Updates rendering resources after a window-size change.
41 * @param window Active rendering window.
42 */
43 void resize(mxvk::VK_Window *window);
44 /**
45 * @brief Advances star movement and twinkling.
46 * @param delta_time Frame duration in seconds.
47 * @param camera_position Current camera position.
48 * @param elapsed_time Total elapsed time in seconds.
49 */
50 void update(float delta_time, const glm::vec3 &camera_position, float elapsed_time);
51 /** @brief Submits the current stars to the assigned sprite batch. */
52 void draw();
53
54 private:
55 std::vector<Star> stars{};
56 mxvk::VK_Sprite3D *sprite = nullptr;
57 bool initialized = false;
58 float min_radius = 50.0f;
59 float max_radius = 200.0f;
60
61 void respawn(Star &star, const glm::vec3 &center);
62 };
63
64} // namespace space
65
66#endif
Shared simulation constants, data types, and utility functions.
Depth-tested 3D billboard sprite batch.
Main Vulkan window wrapper for MXVK.
Definition mxvk.hpp:37
void init(int star_count, float min_radius, float max_radius)
Creates the stars.
Definition starfield.cpp:7
void setSprite(mxvk::VK_Sprite3D *sprite_batch)
Assigns the non-owning sprite batch used to render stars.
Definition starfield.cpp:21
void update(float delta_time, const glm::vec3 &camera_position, float elapsed_time)
Advances star movement and twinkling.
Definition starfield.cpp:31
StarField()=default
Creates an uninitialized starfield.
void resize(mxvk::VK_Window *window)
Updates rendering resources after a window-size change.
Definition starfield.cpp:25
void draw()
Submits the current stars to the assigned sprite batch.
Definition starfield.cpp:50
Utilities for loading and saving PNG images.
Definition mxvk.hpp:30
Runtime state for one animated background star.