feat(starfield3d): camp d'estrelles 3D amb octaedres rotants cap a càmera
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
// starfield3d.hpp - Camp de estrelles 3D real per a l'escena de títol
|
||||
// © 2026 JailDesigner
|
||||
//
|
||||
// Equivalent 3D del `Graphics::Starfield`. Cada estrella és un octaedre
|
||||
// wireframe situat en l'espai mundial (Vec3). Es desplacen cap a la càmera
|
||||
// (Z disminueix); quan creuen el pla Z_NEAR_RESPAWN es regeneren a Z_FAR_SPAWN
|
||||
// amb X/Y aleatori. Cada octaedre rota lentament sobre Y i X per donar volum.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "core/graphics/camera3d.hpp"
|
||||
#include "core/graphics/wireframe3d.hpp"
|
||||
#include "core/rendering/render_context.hpp"
|
||||
#include "core/types.hpp"
|
||||
|
||||
namespace Graphics {
|
||||
|
||||
class Starfield3D {
|
||||
public:
|
||||
Starfield3D(Rendering::Renderer* renderer, const Camera3D* camera, int density = 200);
|
||||
|
||||
void update(float delta_time);
|
||||
void draw() const;
|
||||
|
||||
void setBrightness(float multiplier);
|
||||
|
||||
private:
|
||||
struct Star {
|
||||
Vec3 position{};
|
||||
float velocity_z{0.0F}; // Negatiu: cap a càmera
|
||||
float rot_phase_y{0.0F};
|
||||
float rot_phase_x{0.0F};
|
||||
float rot_speed_y{0.0F};
|
||||
float rot_speed_x{0.0F};
|
||||
float scale{1.0F};
|
||||
};
|
||||
|
||||
static void initStar(Star& star, bool spawn_at_far);
|
||||
[[nodiscard]] auto computeBrightness(const Star& star) const -> float;
|
||||
|
||||
Rendering::Renderer* renderer_;
|
||||
const Camera3D* camera_;
|
||||
std::vector<Star> stars_;
|
||||
Mesh3D octahedron_;
|
||||
float brightness_mult_{1.0F};
|
||||
|
||||
// Volum de spawn / regeneració en l'espai 3D.
|
||||
static constexpr float Z_NEAR_RESPAWN = 5.0F; // Si Z < aquest valor → regenera
|
||||
static constexpr float Z_FAR_SPAWN = 800.0F; // Z de regeneració (lluny)
|
||||
static constexpr float HALF_SPAWN_X = 600.0F; // X aleatori dins [-, +]
|
||||
static constexpr float HALF_SPAWN_Y = 360.0F; // Y aleatori dins [-, +]
|
||||
|
||||
// Mida i moviment.
|
||||
static constexpr float STAR_BASE_SCALE = 1.8F;
|
||||
static constexpr float STAR_SCALE_JITTER = 0.6F;
|
||||
static constexpr float MIN_VELOCITY_Z = 80.0F;
|
||||
static constexpr float MAX_VELOCITY_Z = 200.0F;
|
||||
static constexpr float MIN_ROT_SPEED = 0.2F;
|
||||
static constexpr float MAX_ROT_SPEED = 0.8F;
|
||||
|
||||
// Brightness en funció de la distància Z (a prop = més brillant).
|
||||
static constexpr float BRIGHTNESS_FAR = 0.15F;
|
||||
static constexpr float BRIGHTNESS_NEAR = 1.0F;
|
||||
};
|
||||
|
||||
} // namespace Graphics
|
||||
Reference in New Issue
Block a user