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>
97 lines
3.5 KiB
C++
97 lines
3.5 KiB
C++
#include "torus_shape.hpp"
|
|
#include "defines.hpp"
|
|
#include <cmath>
|
|
|
|
void TorusShape::generatePoints(int num_points, float screen_width, float screen_height) {
|
|
num_points_ = num_points;
|
|
major_radius_ = screen_height * TORUS_MAJOR_RADIUS_FACTOR;
|
|
minor_radius_ = screen_height * TORUS_MINOR_RADIUS_FACTOR;
|
|
// Las posiciones 3D se calculan en getPoint3D() usando ecuaciones paramétricas del torus
|
|
}
|
|
|
|
void TorusShape::update(float delta_time, float screen_width, float screen_height) {
|
|
// Recalcular radios por si cambió resolución (F4)
|
|
major_radius_ = screen_height * TORUS_MAJOR_RADIUS_FACTOR;
|
|
minor_radius_ = screen_height * TORUS_MINOR_RADIUS_FACTOR;
|
|
|
|
// Actualizar ángulos de rotación (triple rotación XYZ)
|
|
angle_x_ += TORUS_ROTATION_SPEED_X * delta_time;
|
|
angle_y_ += TORUS_ROTATION_SPEED_Y * delta_time;
|
|
angle_z_ += TORUS_ROTATION_SPEED_Z * delta_time;
|
|
}
|
|
|
|
void TorusShape::getPoint3D(int index, float& x, float& y, float& z) const {
|
|
// Distribuir puntos uniformemente en la superficie del torus
|
|
// Usamos distribución aproximadamente uniforme basada en área
|
|
|
|
// Calcular número aproximado de anillos y puntos por anillo
|
|
int num_rings = static_cast<int>(sqrtf(static_cast<float>(num_points_) * 0.5f));
|
|
if (num_rings < 2) num_rings = 2;
|
|
|
|
int points_per_ring = num_points_ / num_rings;
|
|
if (points_per_ring < 3) points_per_ring = 3;
|
|
|
|
// Obtener parámetros u y v del índice
|
|
int ring = index / points_per_ring;
|
|
int point_in_ring = index % points_per_ring;
|
|
|
|
// Si nos pasamos del número de anillos, usar el último
|
|
if (ring >= num_rings) {
|
|
ring = num_rings - 1;
|
|
point_in_ring = index - (ring * points_per_ring);
|
|
if (point_in_ring >= points_per_ring) {
|
|
point_in_ring = points_per_ring - 1;
|
|
}
|
|
}
|
|
|
|
// Parámetros u y v normalizados [0, 2π]
|
|
float u = (static_cast<float>(ring) / static_cast<float>(num_rings)) * 2.0f * PI;
|
|
float v = (static_cast<float>(point_in_ring) / static_cast<float>(points_per_ring)) * 2.0f * PI;
|
|
|
|
// Ecuaciones paramétricas del torus
|
|
// x = (R + r*cos(v)) * cos(u)
|
|
// y = (R + r*cos(v)) * sin(u)
|
|
// z = r * sin(v)
|
|
float cos_v = cosf(v);
|
|
float sin_v = sinf(v);
|
|
float cos_u = cosf(u);
|
|
float sin_u = sinf(u);
|
|
|
|
float radius_at_v = major_radius_ + minor_radius_ * cos_v;
|
|
|
|
float x_base = radius_at_v * cos_u;
|
|
float y_base = radius_at_v * sin_u;
|
|
float z_base = minor_radius_ * sin_v;
|
|
|
|
// Aplicar rotación en eje X
|
|
float cos_x = cosf(angle_x_);
|
|
float sin_x = sinf(angle_x_);
|
|
float y_rot_x = y_base * cos_x - z_base * sin_x;
|
|
float z_rot_x = y_base * sin_x + z_base * cos_x;
|
|
|
|
// Aplicar rotación en eje Y
|
|
float cos_y = cosf(angle_y_);
|
|
float sin_y = sinf(angle_y_);
|
|
float x_rot_y = x_base * cos_y - z_rot_x * sin_y;
|
|
float z_rot_y = x_base * sin_y + z_rot_x * cos_y;
|
|
|
|
// Aplicar rotación en eje Z
|
|
float cos_z = cosf(angle_z_);
|
|
float sin_z = sinf(angle_z_);
|
|
float x_final = x_rot_y * cos_z - y_rot_x * sin_z;
|
|
float y_final = x_rot_y * sin_z + y_rot_x * cos_z;
|
|
|
|
// Retornar coordenadas finales rotadas
|
|
x = x_final;
|
|
y = y_final;
|
|
z = z_rot_y;
|
|
}
|
|
|
|
float TorusShape::getScaleFactor(float screen_height) const {
|
|
// Factor de escala para física: proporcional al radio mayor
|
|
// Radio mayor base = 60px (0.25 * 240px en resolución 320x240)
|
|
const float BASE_RADIUS = 60.0f;
|
|
float current_radius = screen_height * TORUS_MAJOR_RADIUS_FACTOR;
|
|
return current_radius / BASE_RADIUS;
|
|
}
|