Mejoras animaciones 3D: tumbling en cilindro + pivoteo en wave grid

- **CylinderShape**: Añadido sistema de tumbling ocasional
  - Volteretas de 90° en eje X cada 3-5 segundos
  - Interpolación suave con ease-in-out (1.5s)
  - Rotación Y continua + tumbling X ocasional = más dinámico

- **WaveGridShape**: Reemplazada rotación por pivoteo sutil
  - Eliminada rotación completa en eje Y
  - Pivoteo en esquinas (oscilación lenta 0.3/0.5 rad/s)
  - Grid paralelo a pantalla con efecto "sábana ondeando"
  - Ondas sinusoidales + pivoteo = movimiento más orgánico

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

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2025-10-04 11:14:29 +02:00
parent af3274e9bc
commit 2ae515592d
4 changed files with 77 additions and 22 deletions

View File

@@ -1,11 +1,15 @@
#include "cylinder_shape.h"
#include "../defines.h"
#include <cmath>
#include <cstdlib> // Para rand()
void CylinderShape::generatePoints(int num_points, float screen_width, float screen_height) {
num_points_ = num_points;
radius_ = screen_height * CYLINDER_RADIUS_FACTOR;
height_ = screen_height * CYLINDER_HEIGHT_FACTOR;
// Inicializar timer de tumbling con valor aleatorio (3-5 segundos)
tumble_timer_ = 3.0f + (rand() % 2000) / 1000.0f;
// Las posiciones 3D se calculan en getPoint3D() usando ecuaciones paramétricas del cilindro
}
@@ -14,8 +18,39 @@ void CylinderShape::update(float delta_time, float screen_width, float screen_he
radius_ = screen_height * CYLINDER_RADIUS_FACTOR;
height_ = screen_height * CYLINDER_HEIGHT_FACTOR;
// Actualizar ángulo de rotación en eje Y
// Actualizar ángulo de rotación en eje Y (siempre activo)
angle_y_ += CYLINDER_ROTATION_SPEED_Y * delta_time;
// Sistema de tumbling ocasional
if (is_tumbling_) {
// Estamos en tumble: animar angle_x hacia el objetivo
tumble_duration_ += delta_time;
float tumble_progress = tumble_duration_ / 1.5f; // 1.5 segundos de duración
if (tumble_progress >= 1.0f) {
// Tumble completado
angle_x_ = tumble_target_;
is_tumbling_ = false;
tumble_timer_ = 3.0f + (rand() % 2000) / 1000.0f; // Nuevo timer (3-5s)
} else {
// Interpolación suave con ease-in-out
float t = tumble_progress;
float ease = t < 0.5f
? 2.0f * t * t
: 1.0f - (-2.0f * t + 2.0f) * (-2.0f * t + 2.0f) / 2.0f;
angle_x_ = ease * tumble_target_;
}
} else {
// No estamos en tumble: contar tiempo
tumble_timer_ -= delta_time;
if (tumble_timer_ <= 0.0f) {
// Iniciar nuevo tumble
is_tumbling_ = true;
tumble_duration_ = 0.0f;
// Objetivo: PI/2 radianes (90°) o -PI/2
tumble_target_ = angle_x_ + ((rand() % 2) == 0 ? PI * 0.5f : -PI * 0.5f);
}
}
}
void CylinderShape::getPoint3D(int index, float& x, float& y, float& z) const {
@@ -56,15 +91,21 @@ void CylinderShape::getPoint3D(int index, float& x, float& y, float& z) const {
float y_base = (height_ * 0.5f) * v; // Centrar verticalmente
float z_base = radius_ * sinf(u);
// Aplicar rotación en eje Y
// Aplicar rotación en eje Y (principal, siempre activa)
float cos_y = cosf(angle_y_);
float sin_y = sinf(angle_y_);
float x_rot = x_base * cos_y - z_base * sin_y;
float z_rot = x_base * sin_y + z_base * cos_y;
float x_rot_y = x_base * cos_y - z_base * sin_y;
float z_rot_y = x_base * sin_y + z_base * cos_y;
// Retornar coordenadas finales rotadas
x = x_rot;
y = y_base;
// Aplicar rotación en eje X (tumbling ocasional)
float cos_x = cosf(angle_x_);
float sin_x = sinf(angle_x_);
float y_rot = y_base * cos_x - z_rot_y * sin_x;
float z_rot = y_base * sin_x + z_rot_y * cos_x;
// Retornar coordenadas finales con ambas rotaciones
x = x_rot_y;
y = y_rot;
z = z_rot;
}