Corregidos ~2570 issues automáticamente con clang-tidy --fix-errors más ajustes manuales posteriores: - modernize: designated-initializers, trailing-return-type, use-auto, avoid-c-arrays (→ std::array<>), use-ranges, use-emplace, deprecated-headers, use-equals-default, pass-by-value, return-braced-init-list, use-default-member-init - readability: math-missing-parentheses, implicit-bool-conversion, braces-around-statements, isolate-declaration, use-std-min-max, identifier-naming, else-after-return, redundant-casting, convert-member-functions-to-static, make-member-function-const, static-accessed-through-instance - performance: avoid-endl, unnecessary-value-param, type-promotion, inefficient-vector-operation - dead code: XOR_KEY (orphan tras eliminar encryptData/decryptData), dead stores en engine.cpp y png_shape.cpp - NOLINT justificado en 10 funciones con alta complejidad cognitiva (initialize, render, main, processEvents, update×3, performDemoAction, randomizeOnDemoStart, renderDebugHUD, AppLogo::update) Compilación: gcc -Wall sin warnings. clang-tidy: 0 issues. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
61 lines
2.2 KiB
C++
61 lines
2.2 KiB
C++
#include "sphere_shape.hpp"
|
|
|
|
#include <cmath>
|
|
|
|
#include "defines.hpp"
|
|
|
|
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;
|
|
}
|
|
|
|
auto SphereShape::getScaleFactor(float screen_height) const -> float {
|
|
// 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;
|
|
}
|