el zoom del LOGO ja es correcte
This commit is contained in:
@@ -6,4 +6,5 @@ name: letra_a
|
|||||||
scale: 1.0
|
scale: 1.0
|
||||||
center: 35.71, 50.00
|
center: 35.71, 50.00
|
||||||
|
|
||||||
polyline: 28.57,71.43 28.57,100.00 0.00,100.00 0.00,14.29 14.29,14.29 14.29,0.00 57.14,0.00 57.14,14.29 71.43,14.29 71.43,100.00 42.86,100.00 42.86,71.43 28.57,14.29 28.57,57.14 42.86,57.14 42.86,14.29
|
polyline: 28.57,71.43 28.57,100.00 0.00,100.00 0.00,14.29 14.29,14.29 14.29,0.00 57.14,0.00 57.14,14.29 71.43,14.29 71.43,100.00 42.86,100.00 42.86,71.43 28.57,71.43
|
||||||
|
polyline: 28.57,14.29 28.57,57.14 42.86,57.14 42.86,14.29 28.57,14.29
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ name: letra_e
|
|||||||
scale: 1.0
|
scale: 1.0
|
||||||
center: 35.71, 50.00
|
center: 35.71, 50.00
|
||||||
|
|
||||||
polyline: 57.14,28.57 57.14,42.86 28.57,42.86 28.57,85.71 71.43,85.71 71.43,100.00 0.00,100.00 0.00,0.00 71.43,0.00 71.43,14.29 28.57,14.29 28.57,28.57
|
polyline: 57.14,28.57 57.14,42.86 28.57,42.86 28.57,85.71 71.43,85.71 71.43,100.00 0.00,100.00 0.00,0.00 71.43,0.00 71.43,14.29 28.57,14.29 28.57,28.57 57.14,28.57
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ name: letra_g
|
|||||||
scale: 1.0
|
scale: 1.0
|
||||||
center: 35.71, 50.00
|
center: 35.71, 50.00
|
||||||
|
|
||||||
polyline: 14.29,0.00 57.14,0.00 57.14,14.29 28.57,14.29 28.57,85.71 42.86,85.71 42.86,42.86 71.43,42.86 71.43,100.00 14.29,100.00 14.29,85.71 0.00,85.71 0.00,14.29 14.29,14.29
|
polyline: 14.29,0.00 57.14,0.00 57.14,14.29 28.57,14.29 28.57,85.71 42.86,85.71 42.86,42.86 71.43,42.86 71.43,100.00 14.29,100.00 14.29,85.71 0.00,85.71 0.00,14.29 14.29,14.29 14.29,0.00
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ name: letra_j
|
|||||||
scale: 1.0
|
scale: 1.0
|
||||||
center: 28.57, 50.00
|
center: 28.57, 50.00
|
||||||
|
|
||||||
polyline: 0.00,100.00 0.00,85.71 28.57,85.71 28.57,0.00 57.14,0.00 57.14,85.71 42.86,85.71 42.86,100.00
|
polyline: 0.00,100.00 0.00,85.71 28.57,85.71 28.57,0.00 57.14,0.00 57.14,85.71 42.86,85.71 42.86,100.00 0.00,100.00
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ name: letra_l
|
|||||||
scale: 1.0
|
scale: 1.0
|
||||||
center: 28.57, 50.00
|
center: 28.57, 50.00
|
||||||
|
|
||||||
polyline: 0.00,0.00 28.57,0.00 28.57,85.71 57.14,85.71 57.14,100.00 0.00,100.00
|
polyline: 0.00,0.00 28.57,0.00 28.57,85.71 57.14,85.71 57.14,100.00 0.00,100.00 0.00,0.00
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ name: letra_m
|
|||||||
scale: 1.0
|
scale: 1.0
|
||||||
center: 50.00, 50.00
|
center: 50.00, 50.00
|
||||||
|
|
||||||
polyline: 71.43,57.14 57.14,57.14 57.14,71.43 42.86,71.43 42.86,57.14 28.57,57.14 28.57,100.00 0.00,100.00 0.00,0.00 14.29,0.00 14.29,14.29 28.57,14.29 28.57,28.57 42.86,28.57 42.86,42.86 57.14,42.86 57.14,28.57 71.43,28.57 71.43,14.29 85.71,14.29 85.71,0.00 100.00,0.00 100.00,100.00 71.43,100.00
|
polyline: 71.43,57.14 57.14,57.14 57.14,71.43 42.86,71.43 42.86,57.14 28.57,57.14 28.57,100.00 0.00,100.00 0.00,0.00 14.29,0.00 14.29,14.29 28.57,14.29 28.57,28.57 42.86,28.57 42.86,42.86 57.14,42.86 57.14,28.57 71.43,28.57 71.43,14.29 85.71,14.29 85.71,0.00 100.00,0.00 100.00,100.00 71.43,100.00 71.43,57.14
|
||||||
|
|||||||
@@ -6,4 +6,4 @@ name: letra_s
|
|||||||
scale: 1.0
|
scale: 1.0
|
||||||
center: 28.57, 50.00
|
center: 28.57, 50.00
|
||||||
|
|
||||||
polyline: 0.00,85.71 28.57,85.71 28.57,57.14 14.29,57.14 14.29,42.86 0.00,42.86 0.00,14.29 14.29,14.29 14.29,0.00 57.14,0.00 57.14,14.29 28.57,14.29 28.57,42.86 42.86,42.86 42.86,57.14 57.14,57.14 57.14,85.71 42.86,85.71 42.86,100.00 0.00,100.00
|
polyline: 0.00,85.71 28.57,85.71 28.57,57.14 14.29,57.14 14.29,42.86 0.00,42.86 0.00,14.29 14.29,14.29 14.29,0.00 57.14,0.00 57.14,14.29 28.57,14.29 28.57,42.86 42.86,42.86 42.86,57.14 57.14,57.14 57.14,85.71 42.86,85.71 42.86,100.00 0.00,100.00 0.00,85.71
|
||||||
|
|||||||
BIN
sample.png
Normal file
BIN
sample.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 36 KiB |
@@ -10,6 +10,32 @@
|
|||||||
#include <cfloat>
|
#include <cfloat>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
|
// Helper: calcular el progrés individual d'una lletra
|
||||||
|
// en funció del progrés global (efecte seqüencial)
|
||||||
|
static float calcular_progress_letra(size_t letra_index,
|
||||||
|
size_t num_letras,
|
||||||
|
float global_progress) {
|
||||||
|
if (num_letras == 0)
|
||||||
|
return 1.0f;
|
||||||
|
|
||||||
|
constexpr float THRESHOLD = 0.5f; // Següent comença al 50%
|
||||||
|
|
||||||
|
// Calcular temps per lletra
|
||||||
|
float duration_per_letra = 1.0f / static_cast<float>(num_letras);
|
||||||
|
float step = THRESHOLD * duration_per_letra;
|
||||||
|
float start = static_cast<float>(letra_index) * step;
|
||||||
|
float end = start + duration_per_letra;
|
||||||
|
|
||||||
|
// Interpolar progrés
|
||||||
|
if (global_progress < start) {
|
||||||
|
return 0.0f; // Encara no ha començat
|
||||||
|
} else if (global_progress >= end) {
|
||||||
|
return 1.0f; // Completament apareguda
|
||||||
|
} else {
|
||||||
|
return (global_progress - start) / (end - start);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
EscenaLogo::EscenaLogo(SDLManager& sdl)
|
EscenaLogo::EscenaLogo(SDLManager& sdl)
|
||||||
: sdl_(sdl), temps_acumulat_(0.0f) {
|
: sdl_(sdl), temps_acumulat_(0.0f) {
|
||||||
std::cout << "Escena Logo: Inicialitzant...\n";
|
std::cout << "Escena Logo: Inicialitzant...\n";
|
||||||
@@ -90,12 +116,18 @@ void EscenaLogo::inicialitzar_lletres() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float ancho = max_x - min_x;
|
float ancho_sin_escalar = max_x - min_x;
|
||||||
|
|
||||||
|
// IMPORTANT: Escalar ancho i offset amb ESCALA_FINAL
|
||||||
|
// per que les posicions finals coincideixin amb la mida real de les lletres
|
||||||
|
float ancho = ancho_sin_escalar * ESCALA_FINAL;
|
||||||
|
float offset_centre = (forma->get_centre().x - min_x) * ESCALA_FINAL;
|
||||||
|
|
||||||
lletres_.push_back({
|
lletres_.push_back({
|
||||||
forma,
|
forma,
|
||||||
{0.0f, 0.0f}, // Posició es calcularà després
|
{0.0f, 0.0f}, // Posició es calcularà després
|
||||||
ancho
|
ancho,
|
||||||
|
offset_centre
|
||||||
});
|
});
|
||||||
|
|
||||||
ancho_total += ancho;
|
ancho_total += ancho;
|
||||||
@@ -115,8 +147,10 @@ void EscenaLogo::inicialitzar_lletres() {
|
|||||||
float x_actual = x_inicial;
|
float x_actual = x_inicial;
|
||||||
|
|
||||||
for (auto& lletra : lletres_) {
|
for (auto& lletra : lletres_) {
|
||||||
// Centre de la lletra en pantalla
|
// Posicionar el centre de la forma (shape_centre) en pantalla
|
||||||
lletra.posicio.x = x_actual + lletra.ancho / 2.0f;
|
// Usar offset_centre en lloc de ancho/2 perquè shape_centre
|
||||||
|
// pot no estar exactament al mig del bounding box
|
||||||
|
lletra.posicio.x = x_actual + lletra.offset_centre;
|
||||||
lletra.posicio.y = y_centre;
|
lletra.posicio.y = y_centre;
|
||||||
|
|
||||||
// Avançar per a següent lletra
|
// Avançar per a següent lletra
|
||||||
@@ -127,22 +161,6 @@ void EscenaLogo::inicialitzar_lletres() {
|
|||||||
<< " lletres carregades, ancho total: " << ancho_total << " px\n";
|
<< " lletres carregades, ancho total: " << ancho_total << " px\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
float EscenaLogo::calcular_escala_zoom(float temps) const {
|
|
||||||
if (temps >= DURACIO_ZOOM) {
|
|
||||||
return ESCALA_FINAL; // Animació acabada
|
|
||||||
}
|
|
||||||
|
|
||||||
// Progrés normalitzat (0.0 a 1.0)
|
|
||||||
float t = temps / DURACIO_ZOOM;
|
|
||||||
|
|
||||||
// Ease-out quadràtic: y = 1 - (1-t)^2
|
|
||||||
// Comença ràpid, acaba suau
|
|
||||||
float factor = 1.0f - (1.0f - t) * (1.0f - t);
|
|
||||||
|
|
||||||
// Interpolar entre escala inicial i final
|
|
||||||
return ESCALA_INICIAL + (ESCALA_FINAL - ESCALA_INICIAL) * factor;
|
|
||||||
}
|
|
||||||
|
|
||||||
void EscenaLogo::actualitzar(float delta_time) {
|
void EscenaLogo::actualitzar(float delta_time) {
|
||||||
temps_acumulat_ += delta_time;
|
temps_acumulat_ += delta_time;
|
||||||
|
|
||||||
@@ -156,18 +174,45 @@ void EscenaLogo::dibuixar() {
|
|||||||
// Fons negre
|
// Fons negre
|
||||||
sdl_.neteja(0, 0, 0);
|
sdl_.neteja(0, 0, 0);
|
||||||
|
|
||||||
// Calcular escala actual del zoom
|
// Progrés global normalitzat (0.0 → 1.0)
|
||||||
float escala = calcular_escala_zoom(temps_acumulat_);
|
float global_progress = std::min(temps_acumulat_ / DURACIO_ZOOM, 1.0f);
|
||||||
|
|
||||||
// Dibuixar cada lletra amb l'escala animada
|
// Centre de la pantalla (punt inicial de totes les lletres)
|
||||||
for (const auto& lletra : lletres_) {
|
constexpr Punt CENTRE_PANTALLA = {640.0f / 2.0f, 480.0f / 2.0f};
|
||||||
|
|
||||||
|
// Dibuixar cada lletra amb animació seqüencial
|
||||||
|
for (size_t i = 0; i < lletres_.size(); i++) {
|
||||||
|
const auto& lletra = lletres_[i];
|
||||||
|
|
||||||
|
// Calcular progrés individual d'aquesta lletra (0.0 → 1.0)
|
||||||
|
float letra_progress = calcular_progress_letra(i, lletres_.size(), global_progress);
|
||||||
|
|
||||||
|
// Si la lletra encara no ha començat, saltar-la
|
||||||
|
if (letra_progress <= 0.0f) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Interpolar posició: des del centre cap a posició final
|
||||||
|
Punt pos_actual;
|
||||||
|
pos_actual.x = CENTRE_PANTALLA.x + (lletra.posicio.x - CENTRE_PANTALLA.x) * letra_progress;
|
||||||
|
pos_actual.y = CENTRE_PANTALLA.y + (lletra.posicio.y - CENTRE_PANTALLA.y) * letra_progress;
|
||||||
|
|
||||||
|
// Aplicar ease-out quadràtic per suavitat
|
||||||
|
float t = letra_progress;
|
||||||
|
float ease_factor = 1.0f - (1.0f - t) * (1.0f - t);
|
||||||
|
|
||||||
|
// Interpolar escala amb ease-out: des de ESCALA_INICIAL cap a ESCALA_FINAL
|
||||||
|
float escala_actual = ESCALA_INICIAL + (ESCALA_FINAL - ESCALA_INICIAL) * ease_factor;
|
||||||
|
|
||||||
|
// Renderitzar la lletra
|
||||||
Rendering::render_shape(
|
Rendering::render_shape(
|
||||||
sdl_.obte_renderer(),
|
sdl_.obte_renderer(),
|
||||||
lletra.forma,
|
lletra.forma,
|
||||||
lletra.posicio, // Posició en pantalla
|
pos_actual, // Posició interpolada
|
||||||
0.0f, // Sense rotació
|
0.0f, // Sense rotació
|
||||||
escala, // Escala animada
|
escala_actual, // Escala interpolada amb ease-out
|
||||||
true // Dibuixar
|
true, // Dibuixar
|
||||||
|
1.0f // Progress = 1.0 (lletra completa, sense animació de primitives)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,22 +23,22 @@ private:
|
|||||||
// Estructura per a cada lletra del logo
|
// Estructura per a cada lletra del logo
|
||||||
struct LetraLogo {
|
struct LetraLogo {
|
||||||
std::shared_ptr<Graphics::Shape> forma;
|
std::shared_ptr<Graphics::Shape> forma;
|
||||||
Punt posicio; // Posició final en pantalla
|
Punt posicio; // Posició final en pantalla
|
||||||
float ancho; // Ancho per a càlcul de centrat
|
float ancho; // Ancho del bounding box
|
||||||
|
float offset_centre; // Distància de min_x a shape_centre.x
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<LetraLogo> lletres_; // 9 lletres: J-A-I-L-G-A-M-E-S
|
std::vector<LetraLogo> lletres_; // 9 lletres: J-A-I-L-G-A-M-E-S
|
||||||
|
|
||||||
// Constants d'animació
|
// Constants d'animació
|
||||||
static constexpr float DURACIO_ZOOM = 1.5f; // Duració del zoom (segons)
|
static constexpr float DURACIO_ZOOM = 4.0f; // Duració del zoom (segons)
|
||||||
static constexpr float DURACIO_TOTAL = 3.0f; // Duració total abans d'anar al joc
|
static constexpr float DURACIO_TOTAL = 20.0f; // Duració total abans d'anar al joc
|
||||||
static constexpr float ESCALA_INICIAL = 0.1f; // Escala inicial (10%)
|
static constexpr float ESCALA_INICIAL = 0.1f; // Escala inicial (10%)
|
||||||
static constexpr float ESCALA_FINAL = 1.0f; // Escala final (100%)
|
static constexpr float ESCALA_FINAL = 0.8f; // Escala final (100%)
|
||||||
static constexpr float ESPAI_ENTRE_LLETRES = 10.0f; // Espaiat entre lletres
|
static constexpr float ESPAI_ENTRE_LLETRES = 10.0f; // Espaiat entre lletres
|
||||||
|
|
||||||
// Mètodes privats
|
// Mètodes privats
|
||||||
void inicialitzar_lletres();
|
void inicialitzar_lletres();
|
||||||
float calcular_escala_zoom(float temps) const;
|
|
||||||
void actualitzar(float delta_time);
|
void actualitzar(float delta_time);
|
||||||
void dibuixar();
|
void dibuixar();
|
||||||
void processar_events(const SDL_Event& event);
|
void processar_events(const SDL_Event& event);
|
||||||
|
|||||||
Reference in New Issue
Block a user