#include "sphere_shape.hpp" #include "defines.hpp" #include 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(index) / static_cast(num_points_); float phi = acosf(1.0f - 2.0f * t); // Latitud float theta = angle_increment * static_cast(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; }