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>
100 lines
3.6 KiB
C++
100 lines
3.6 KiB
C++
#include "torus_shape.hpp"
|
|
|
|
#include <algorithm>
|
|
#include <cmath>
|
|
|
|
#include "defines.hpp"
|
|
|
|
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));
|
|
num_rings = std::max(num_rings, 2);
|
|
|
|
int points_per_ring = num_points_ / num_rings;
|
|
points_per_ring = std::max(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;
|
|
}
|
|
|
|
auto TorusShape::getScaleFactor(float screen_height) const -> float {
|
|
// 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;
|
|
}
|