refactor(title): la 3D és l'única — elimina backup 2D i renomena als noms canònics
This commit is contained in:
1 parent
a29c2b9cc2
commit
54d3e683a1
16 files changed
+680
-2321
No files matched your search
@@ -1,104 +1,85 @@
|
||||
// ship_animator.hpp - Sistema de animación de naves para l'escena de título
|
||||
// ship_animator.hpp - Sistema d'animació de naus 3D per a l'escena de títol
|
||||
// © 2026 JailDesigner
|
||||
//
|
||||
// Manté la mateixa màquina d'estats
|
||||
// (ENTERING → FLOATING → EXITING) però treballa amb posicions Vec3 i emet
|
||||
// wireframes a través d'una `Camera3D`. La geometria s'extrau de `ship.shp`
|
||||
// (P1) i `ship2.shp` (P2) per extrusió en Z.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/rendering/render_context.hpp"
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
|
||||
#include "core/graphics/shape.hpp"
|
||||
#include "core/graphics/camera3d.hpp"
|
||||
#include "core/graphics/wireframe3d.hpp"
|
||||
#include "core/rendering/render_context.hpp"
|
||||
#include "core/types.hpp"
|
||||
|
||||
namespace Title {
|
||||
|
||||
// Estats de l'animación de la ship
|
||||
enum class ShipState : std::uint8_t {
|
||||
ENTERING, // Entrant desde fuera de pantalla
|
||||
FLOATING, // Flotante en posición estàtica
|
||||
EXITING // Volant hacia el point de fuga
|
||||
};
|
||||
enum class ShipState : std::uint8_t {
|
||||
ENTERING,
|
||||
FLOATING,
|
||||
EXITING,
|
||||
};
|
||||
|
||||
// Dades de una ship individual al título.
|
||||
// Todos los miembros tienen inicializador por defecto: ShipAnimator::ships_
|
||||
// es un std::array<TitleShip, 2> y sin estos defaults los campos primitivos
|
||||
// quedarían indeterminados al instanciar el animador.
|
||||
struct TitleShip {
|
||||
// Identificació
|
||||
int player_id{0}; // 1 o 2
|
||||
|
||||
// Estat
|
||||
struct TitleShip {
|
||||
int player_id{0};
|
||||
ShipState state{ShipState::ENTERING};
|
||||
float state_time{0.0F}; // Temps acumulat en l'state actual
|
||||
float state_time{0.0F};
|
||||
|
||||
// Posicions
|
||||
Vec2 initial_position{}; // Posición de start (fuera de pantalla per ENTERING)
|
||||
Vec2 target_position{}; // Posición objetivo (rellotge 8 o 4)
|
||||
Vec2 current_position{}; // Posición interpolada actual
|
||||
Vec3 initial_position{};
|
||||
Vec3 target_position{};
|
||||
Vec3 current_position{};
|
||||
|
||||
// Escales (simulació eix Z)
|
||||
float initial_scale{1.0F}; // Escala de start (més grande = més a prop)
|
||||
float target_scale{1.0F}; // Escala objetivo (mida flotació)
|
||||
float current_scale{1.0F}; // Escala interpolada actual
|
||||
float initial_scale{1.0F};
|
||||
float target_scale{1.0F};
|
||||
float current_scale{1.0F};
|
||||
|
||||
// Flotació
|
||||
float oscillation_phase{0.0F}; // Acumulador de fase per movement sinusoïdal
|
||||
float oscillation_phase{0.0F};
|
||||
float entry_delay{0.0F};
|
||||
|
||||
// Parámetros de entrada
|
||||
float entry_delay{0.0F}; // Delay antes de entrar (0.0 per P1, 0.5 per P2)
|
||||
|
||||
// Parámetros de oscil·lació per ship
|
||||
float amplitude_x{0.0F};
|
||||
float amplitude_y{0.0F};
|
||||
float frequency_x{0.0F};
|
||||
float frequency_y{0.0F};
|
||||
|
||||
// Forma
|
||||
std::shared_ptr<Graphics::Shape> shape;
|
||||
|
||||
// Visibilitat
|
||||
Graphics::Mesh3D mesh;
|
||||
// Vector mundial cap a on apunta el front del shape. Recalculat a cada
|
||||
// transició d'estat perquè draw() oriente la nau (look-at) en la
|
||||
// direcció del seu path actual.
|
||||
Vec3 forward_dir{.x = 0.0F, .y = 0.0F, .z = 1.0F};
|
||||
bool visible{false};
|
||||
};
|
||||
};
|
||||
|
||||
// Gestor de animación de naves para l'escena de título
|
||||
class ShipAnimator {
|
||||
public:
|
||||
explicit ShipAnimator(Rendering::Renderer* renderer);
|
||||
class ShipAnimator {
|
||||
public:
|
||||
ShipAnimator(Rendering::Renderer* renderer, const Graphics::Camera3D* camera);
|
||||
|
||||
// Cicle de vida
|
||||
void init();
|
||||
void update(float delta_time);
|
||||
void draw() const;
|
||||
|
||||
// Control de state (cridat per TitleScene)
|
||||
void startEntryAnimation();
|
||||
void triggerExitAnimation(); // Anima todas las naves
|
||||
void triggerExitAnimationForPlayer(int player_id); // Anima solo una ship (P1=1, P2=2)
|
||||
void skipToFloatingState(); // Salta directament a FLOATING sin animación
|
||||
void triggerExitAnimation();
|
||||
void triggerExitAnimationForPlayer(int player_id);
|
||||
void skipToFloatingState();
|
||||
|
||||
// Control de visibilitat
|
||||
void setVisible(bool visible);
|
||||
[[nodiscard]] auto isAnimationComplete() const -> bool;
|
||||
[[nodiscard]] auto isVisible() const -> bool; // Comprova si alguna ship es visible
|
||||
[[nodiscard]] auto isVisible() const -> bool;
|
||||
|
||||
private:
|
||||
private:
|
||||
Rendering::Renderer* renderer_;
|
||||
std::array<TitleShip, 2> ships_; // Naves P1 i P2
|
||||
const Graphics::Camera3D* camera_;
|
||||
std::array<TitleShip, 2> ships_;
|
||||
|
||||
// Métodos de animación. Estáticos: solo modifican el TitleShip pasado,
|
||||
// sin tocar otros miembros del ShipAnimator.
|
||||
static void updateEntering(TitleShip& ship, float delta_time);
|
||||
static void updateFloating(TitleShip& ship, float delta_time);
|
||||
static void updateExiting(TitleShip& ship, float delta_time);
|
||||
|
||||
// Configuración (también estáticos: trabajan sobre el ship pasado).
|
||||
static void configureShipP1(TitleShip& ship);
|
||||
static void configureShipP2(TitleShip& ship);
|
||||
[[nodiscard]] static auto computeOffscreenPosition(float angle_rellotge) -> Vec2;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace Title
|
||||
Reference in new issue
Block a user