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>
59 lines
2.1 KiB
C++
59 lines
2.1 KiB
C++
#include "sphere_shape.hpp"
|
|
#include "defines.hpp"
|
|
#include <cmath>
|
|
|
|
void SphereShape::generatePoints(int num_points, float screen_width, float screen_height) {
|
|
num_points_ = num_points;
|
|
radius_ = screen_height * ROTOBALL_RADIUS_FACTOR;
|
|
// Las posiciones 3D se calculan en getPoint3D() usando Fibonacci Sphere
|
|
}
|
|
|
|
void SphereShape::update(float delta_time, float screen_width, float screen_height) {
|
|
// Recalcular radio por si cambió resolución (F4)
|
|
radius_ = screen_height * ROTOBALL_RADIUS_FACTOR;
|
|
|
|
// Actualizar ángulos de rotación
|
|
angle_y_ += ROTOBALL_ROTATION_SPEED_Y * delta_time;
|
|
angle_x_ += ROTOBALL_ROTATION_SPEED_X * delta_time;
|
|
}
|
|
|
|
void SphereShape::getPoint3D(int index, float& x, float& y, float& z) const {
|
|
// Algoritmo Fibonacci Sphere para distribución uniforme
|
|
const float golden_ratio = (1.0f + sqrtf(5.0f)) / 2.0f;
|
|
const float angle_increment = PI * 2.0f * golden_ratio;
|
|
|
|
float t = static_cast<float>(index) / static_cast<float>(num_points_);
|
|
float phi = acosf(1.0f - 2.0f * t); // Latitud
|
|
float theta = angle_increment * static_cast<float>(index); // Longitud
|
|
|
|
// Convertir coordenadas esféricas a cartesianas
|
|
float x_base = cosf(theta) * sinf(phi) * radius_;
|
|
float y_base = sinf(theta) * sinf(phi) * radius_;
|
|
float z_base = cosf(phi) * radius_;
|
|
|
|
// Aplicar rotación en eje Y
|
|
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;
|
|
|
|
// Aplicar rotación en eje X
|
|
float cos_x = cosf(angle_x_);
|
|
float sin_x = sinf(angle_x_);
|
|
float y_rot = y_base * cos_x - z_rot * sin_x;
|
|
float z_final = y_base * sin_x + z_rot * cos_x;
|
|
|
|
// Retornar coordenadas finales rotadas
|
|
x = x_rot;
|
|
y = y_rot;
|
|
z = z_final;
|
|
}
|
|
|
|
float SphereShape::getScaleFactor(float screen_height) const {
|
|
// Factor de escala para física: proporcional al radio
|
|
// Radio base = 80px (resolución 320x240)
|
|
const float BASE_RADIUS = 80.0f;
|
|
float current_radius = screen_height * ROTOBALL_RADIUS_FACTOR;
|
|
return current_radius / BASE_RADIUS;
|
|
}
|