Reemplazar Wave Grid por Lissajous Curve 3D

Cambiar figura "Wave Grid" (malla ondeante) por curva de Lissajous 3D,
con ecuaciones paramétricas más hipnóticas y resultónas visualmente.

## Cambios Principales

**Archivos renombrados:**
- `wave_grid_shape.h/cpp` → `lissajous_shape.h/cpp`
- Clase `WaveGridShape` → `LissajousShape`

**Ecuaciones implementadas:**
- x(t) = A * sin(3t + φx)  - Frecuencia 3 en X
- y(t) = A * sin(2t)       - Frecuencia 2 en Y
- z(t) = A * sin(t + φz)   - Frecuencia 1 en Z
- Ratio 3:2:1 produce patrón de "trenza elegante"

**Animación:**
- Rotación global dual (ejes X/Y)
- Animación de fase continua (morphing)
- Más dinámica y orgánica que Wave Grid

**defines.h:**
- `WAVE_GRID_*` → `LISSAJOUS_*` constantes
- `ShapeType::WAVE_GRID` → `ShapeType::LISSAJOUS`

**engine.cpp:**
- Actualizado include y instanciación
- Arrays de figuras DEMO actualizados
- Tecla W ahora activa Lissajous

## Resultado

Curva 3D paramétrica hipnótica con patrón entrelazado,
rotación continua y morphing de fase. Más espectacular
que el grid ondeante anterior. 🌀

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-07 12:31:38 +02:00
parent c55d6de687
commit 6cb3c2eef9
8 changed files with 233 additions and 232 deletions

View File

@@ -0,0 +1,64 @@
#include "lissajous_shape.h"
#include "../defines.h"
#include <cmath>
void LissajousShape::generatePoints(int num_points, float screen_width, float screen_height) {
num_points_ = num_points;
amplitude_ = screen_height * LISSAJOUS_SIZE_FACTOR;
// Inicializar frecuencias desde defines.h
freq_x_ = LISSAJOUS_FREQ_X;
freq_y_ = LISSAJOUS_FREQ_Y;
freq_z_ = LISSAJOUS_FREQ_Z;
}
void LissajousShape::update(float delta_time, float screen_width, float screen_height) {
// Recalcular amplitud por si cambió resolución (F4)
amplitude_ = screen_height * LISSAJOUS_SIZE_FACTOR;
// Actualizar rotación global
rotation_x_ += LISSAJOUS_ROTATION_SPEED_X * delta_time;
rotation_y_ += LISSAJOUS_ROTATION_SPEED_Y * delta_time;
// Actualizar fase para animación (morphing de la curva)
phase_x_ += LISSAJOUS_PHASE_SPEED * delta_time;
phase_z_ += LISSAJOUS_PHASE_SPEED * delta_time * 0.7f; // Z rota más lento para variación
}
void LissajousShape::getPoint3D(int index, float& x, float& y, float& z) const {
// Mapear índice [0, num_points-1] a parámetro t [0, 2π]
float t = (static_cast<float>(index) / static_cast<float>(num_points_)) * 2.0f * PI;
// Ecuaciones de Lissajous 3D
// x(t) = A * sin(freq_x * t + phase_x)
// y(t) = A * sin(freq_y * t)
// z(t) = A * sin(freq_z * t + phase_z)
float x_local = amplitude_ * sinf(freq_x_ * t + phase_x_);
float y_local = amplitude_ * sinf(freq_y_ * t);
float z_local = amplitude_ * sinf(freq_z_ * t + phase_z_);
// Aplicar rotación global en eje X
float cos_x = cosf(rotation_x_);
float sin_x = sinf(rotation_x_);
float y_rot = y_local * cos_x - z_local * sin_x;
float z_rot = y_local * sin_x + z_local * cos_x;
// Aplicar rotación global en eje Y
float cos_y = cosf(rotation_y_);
float sin_y = sinf(rotation_y_);
float x_final = x_local * cos_y - z_rot * sin_y;
float z_final = x_local * sin_y + z_rot * cos_y;
// Retornar coordenadas rotadas
x = x_final;
y = y_rot;
z = z_final;
}
float LissajousShape::getScaleFactor(float screen_height) const {
// Factor de escala para física: proporcional a la amplitud de la curva
// Amplitud base = 84px (0.35 * 240px en resolución 320x240)
const float BASE_SIZE = 84.0f;
float current_size = screen_height * LISSAJOUS_SIZE_FACTOR;
return current_size / BASE_SIZE;
}

View File

@@ -0,0 +1,26 @@
#pragma once
#include "shape.h"
// Figura: Curva de Lissajous 3D
// Comportamiento: Curva paramétrica 3D con rotación global y animación de fase
// Ecuaciones: x(t) = A*sin(freq_x*t + phase_x), y(t) = A*sin(freq_y*t), z(t) = A*sin(freq_z*t + phase_z)
class LissajousShape : public Shape {
private:
float freq_x_ = 0.0f; // Frecuencia en eje X
float freq_y_ = 0.0f; // Frecuencia en eje Y
float freq_z_ = 0.0f; // Frecuencia en eje Z
float phase_x_ = 0.0f; // Desfase X (animado)
float phase_z_ = 0.0f; // Desfase Z (animado)
float rotation_x_ = 0.0f; // Rotación global en eje X (rad)
float rotation_y_ = 0.0f; // Rotación global en eje Y (rad)
float amplitude_ = 0.0f; // Amplitud de la curva (píxeles)
int num_points_ = 0; // Cantidad total de puntos
public:
void generatePoints(int num_points, float screen_width, float screen_height) override;
void update(float delta_time, float screen_width, float screen_height) override;
void getPoint3D(int index, float& x, float& y, float& z) const override;
const char* getName() const override { return "LISSAJOUS"; }
float getScaleFactor(float screen_height) const override;
};

View File

@@ -267,7 +267,7 @@ std::vector<PNGShape::Point2D> PNGShape::extractCornerVertices(const std::vector
void PNGShape::update(float delta_time, float screen_width, float screen_height) {
if (!is_flipping_) {
// Estado IDLE: texto de frente con pivoteo sutil (como WAVE_GRID)
// Estado IDLE: texto de frente con pivoteo sutil
idle_timer_ += delta_time;
// Pivoteo sutil constante (movimiento orgánico)
@@ -340,7 +340,7 @@ void PNGShape::getPoint3D(int index, float& x, float& y, float& z) const {
z_base = -extrusion_depth_ * 0.5f + layer_index * layer_step;
}
// Añadir pivoteo sutil en estado IDLE (similar a WAVE_GRID)
// Añadir pivoteo sutil en estado IDLE
// Calcular tamaño del logo en pantalla para normalizar correctamente
float logo_width = image_width_ * scale_factor_;
float logo_height = image_height_ * scale_factor_;
@@ -350,9 +350,9 @@ void PNGShape::getPoint3D(int index, float& x, float& y, float& z) const {
float u = x_base / (logo_size * 0.5f);
float v = y_base / (logo_size * 0.5f);
// Calcular pivoteo (amplitudes más grandes, similar a WAVE_GRID)
float tilt_amount_x = sinf(tilt_x_) * 0.15f; // 15% como WAVE_GRID
float tilt_amount_y = sinf(tilt_y_) * 0.1f; // 10% como WAVE_GRID
// Calcular pivoteo (amplitudes más grandes)
float tilt_amount_x = sinf(tilt_x_) * 0.15f; // 15%
float tilt_amount_y = sinf(tilt_y_) * 0.1f; // 10%
// Aplicar pivoteo proporcional al tamaño del logo
float z_tilt = (u * tilt_amount_y + v * tilt_amount_x) * logo_size;

View File

@@ -36,7 +36,7 @@ private:
bool is_flipping_ = false; // Estado: quieto o voltereta
int flip_axis_ = 0; // Eje de voltereta (0=X, 1=Y, 2=ambos)
// Pivoteo sutil en estado IDLE (similar a WAVE_GRID)
// Pivoteo sutil en estado IDLE
float tilt_x_ = 0.0f; // Oscilación sutil en eje X
float tilt_y_ = 0.0f; // Oscilación sutil en eje Y

View File

@@ -1,99 +0,0 @@
#include "wave_grid_shape.h"
#include "../defines.h"
#include <cmath>
void WaveGridShape::generatePoints(int num_points, float screen_width, float screen_height) {
num_points_ = num_points;
grid_size_ = screen_height * WAVE_GRID_SIZE_FACTOR;
amplitude_ = screen_height * WAVE_GRID_AMPLITUDE;
// Calcular grid cuadrado aproximado basado en número de puntos
// Queremos grid_cols * grid_rows ≈ num_points
grid_cols_ = static_cast<int>(sqrtf(static_cast<float>(num_points)));
grid_rows_ = grid_cols_;
// Ajustar para que grid_cols * grid_rows no exceda num_points
while (grid_cols_ * grid_rows_ > num_points && grid_rows_ > 1) {
grid_rows_--;
}
// Si tenemos menos puntos que celdas, ajustar columnas también
if (grid_cols_ * grid_rows_ > num_points) {
grid_cols_ = num_points / grid_rows_;
}
// Casos especiales para pocos puntos
if (num_points < 4) {
grid_cols_ = num_points;
grid_rows_ = 1;
}
}
void WaveGridShape::update(float delta_time, float screen_width, float screen_height) {
// Recalcular dimensiones por si cambió resolución (F4)
grid_size_ = screen_height * WAVE_GRID_SIZE_FACTOR;
amplitude_ = screen_height * WAVE_GRID_AMPLITUDE;
// Pivoteo sutil en ejes X e Y (esquinas adelante/atrás, izq/der)
// Usamos velocidades lentas para movimiento sutil y orgánico
tilt_x_ += 0.3f * delta_time; // Pivoteo vertical (esquinas arriba/abajo)
tilt_y_ += 0.5f * delta_time; // Pivoteo horizontal (esquinas izq/der)
// Actualizar fase de las ondas (animación)
phase_ += WAVE_GRID_PHASE_SPEED * delta_time;
}
void WaveGridShape::getPoint3D(int index, float& x, float& y, float& z) const {
// Convertir índice lineal a coordenadas 2D del grid
int col = index % grid_cols_;
int row = index / grid_cols_;
// Si el índice está fuera del grid válido, colocar en origen
if (row >= grid_rows_) {
x = 0.0f;
y = 0.0f;
z = 0.0f;
return;
}
// Normalizar coordenadas del grid a rango [-1, 1]
float u = (static_cast<float>(col) / static_cast<float>(grid_cols_ - 1)) * 2.0f - 1.0f;
float v = (static_cast<float>(row) / static_cast<float>(grid_rows_ - 1)) * 2.0f - 1.0f;
// Casos especiales para grids de 1 columna/fila
if (grid_cols_ == 1) u = 0.0f;
if (grid_rows_ == 1) v = 0.0f;
// Posición base en el grid (escalada por tamaño)
float x_base = u * grid_size_;
float y_base = v * grid_size_;
// Calcular Z usando función de onda 2D
// z = amplitude * sin(frequency * x + phase) * cos(frequency * y + phase)
float kx = WAVE_GRID_FREQUENCY * PI; // Frecuencia en X
float ky = WAVE_GRID_FREQUENCY * PI; // Frecuencia en Y
float z_wave = amplitude_ * sinf(kx * u + phase_) * cosf(ky * v + phase_);
// Añadir pivoteo sutil: esquinas se mueven adelante/atrás según posición
// tilt_x oscila esquinas arriba/abajo, tilt_y oscila esquinas izq/der
float tilt_amount_x = sinf(tilt_x_) * 0.15f; // Máximo 15% del grid_size
float tilt_amount_y = sinf(tilt_y_) * 0.1f; // Máximo 10% del grid_size
float z_tilt = (u * tilt_amount_y + v * tilt_amount_x) * grid_size_;
// Z final = ondas + pivoteo
float z_final = z_wave + z_tilt;
// Retornar coordenadas (grid paralelo a pantalla, sin rotación global)
x = x_base;
y = y_base;
z = z_final;
}
float WaveGridShape::getScaleFactor(float screen_height) const {
// Factor de escala para física: proporcional al tamaño del grid
// Grid base = 84px (0.35 * 240px en resolución 320x240)
const float BASE_SIZE = 84.0f;
float current_size = screen_height * WAVE_GRID_SIZE_FACTOR;
return current_size / BASE_SIZE;
}

View File

@@ -1,25 +0,0 @@
#pragma once
#include "shape.h"
// Figura: Malla ondeante 3D (Wave Grid)
// Comportamiento: Grid 2D paralelo a pantalla con ondas + pivoteo sutil en esquinas
// Ecuaciones: z = A * sin(kx*x + phase) * cos(ky*y + phase) + pivoteo
class WaveGridShape : public Shape {
private:
float tilt_x_ = 0.0f; // Ángulo de pivoteo en eje X (esquinas adelante/atrás)
float tilt_y_ = 0.0f; // Ángulo de pivoteo en eje Y (esquinas izq/der)
float phase_ = 0.0f; // Fase de animación de ondas (rad)
float grid_size_ = 0.0f; // Tamaño del grid (píxeles)
float amplitude_ = 0.0f; // Amplitud de las ondas (píxeles)
int grid_cols_ = 0; // Número de columnas del grid
int grid_rows_ = 0; // Número de filas del grid
int num_points_ = 0; // Cantidad total de puntos
public:
void generatePoints(int num_points, float screen_width, float screen_height) override;
void update(float delta_time, float screen_width, float screen_height) override;
void getPoint3D(int index, float& x, float& y, float& z) const override;
const char* getName() const override { return "WAVE GRID"; }
float getScaleFactor(float screen_height) const override;
};