Files
vibe3_physics/source/shapes/helix_shape.cpp
Sergio Valor a9d7b66e83 Refactorizar estilo del proyecto: .h → .hpp, #pragma once, includes desde raíz
Modernizar convenciones de código C++ aplicando las siguientes directivas:

## Cambios principales

**1. Renombrar headers (.h → .hpp)**
- 36 archivos renombrados a extensión .hpp (estándar C++)
- Mantenidos como .h: stb_image.h, stb_image_resize2.h (librerías C externas)

**2. Modernizar include guards (#ifndef → #pragma once)**
- resource_manager.hpp: #ifndef RESOURCE_MANAGER_H → #pragma once
- resource_pack.hpp: #ifndef RESOURCE_PACK_H → #pragma once
- spatial_grid.hpp: #ifndef SPATIAL_GRID_H → #pragma once

**3. Sistema de includes desde raíz del proyecto**
- CMakeLists.txt: añadido include_directories(${CMAKE_SOURCE_DIR}/source)
- Eliminadas rutas relativas (../) en todos los includes
- Includes ahora usan rutas absolutas desde source/

**Antes:**
```cpp
#include "../defines.h"
#include "../text/textrenderer.h"
```

**Ahora:**
```cpp
#include "defines.hpp"
#include "text/textrenderer.hpp"
```

## Archivos afectados

- 1 archivo CMakeLists.txt modificado
- 36 archivos renombrados (.h → .hpp)
- 32 archivos .cpp actualizados (includes)
- 36 archivos .hpp actualizados (includes + guards)
- 1 archivo tools/ actualizado

**Total: 70 archivos modificados**

## Verificación

 Proyecto compila sin errores
 Todas las rutas de includes correctas
 Include guards modernizados
 Librerías externas C mantienen extensión .h

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

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-23 13:49:58 +02:00

60 lines
2.3 KiB
C++

#include "helix_shape.hpp"
#include "defines.hpp"
#include <cmath>
void HelixShape::generatePoints(int num_points, float screen_width, float screen_height) {
num_points_ = num_points;
radius_ = screen_height * HELIX_RADIUS_FACTOR;
pitch_ = screen_height * HELIX_PITCH_FACTOR;
total_height_ = pitch_ * HELIX_NUM_TURNS;
// Las posiciones 3D se calculan en getPoint3D() usando ecuaciones paramétricas
}
void HelixShape::update(float delta_time, float screen_width, float screen_height) {
// Recalcular dimensiones por si cambió resolución (F4)
radius_ = screen_height * HELIX_RADIUS_FACTOR;
pitch_ = screen_height * HELIX_PITCH_FACTOR;
total_height_ = pitch_ * HELIX_NUM_TURNS;
// Actualizar rotación en eje Y (horizontal)
angle_y_ += HELIX_ROTATION_SPEED_Y * delta_time;
// Actualizar fase para animación vertical (efecto "subiendo/bajando")
phase_offset_ += HELIX_PHASE_SPEED * delta_time;
}
void HelixShape::getPoint3D(int index, float& x, float& y, float& z) const {
// Parámetro t: distribuir uniformemente de 0 a (2π * num_turns)
float t = (static_cast<float>(index) / static_cast<float>(num_points_)) * (2.0f * PI * HELIX_NUM_TURNS);
// Ecuaciones paramétricas de hélice
// x = radius * cos(t)
// y = pitch * (t / 2π) + phase_offset (altura proporcional al ángulo)
// z = radius * sin(t)
float x_base = radius_ * cosf(t);
float y_base = (pitch_ * (t / (2.0f * PI))) + (sinf(phase_offset_) * pitch_ * 0.3f);
float z_base = radius_ * sinf(t);
// Centrar verticalmente: restar mitad de altura total
y_base -= total_height_ * 0.5f;
// Aplicar rotación en eje Y (horizontal)
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;
// Retornar coordenadas finales
x = x_rot;
y = y_base;
z = z_rot;
}
float HelixShape::getScaleFactor(float screen_height) const {
// Factor de escala para física: proporcional a la dimensión mayor (altura total)
// Altura base = 180px para 3 vueltas con pitch=0.25 en 240px de altura (180 = 240 * 0.25 * 3)
const float BASE_HEIGHT = 180.0f;
float current_height = screen_height * HELIX_PITCH_FACTOR * HELIX_NUM_TURNS;
return current_height / BASE_HEIGHT;
}