Implementar sistema polimórfico de figuras 3D (Sphere + Cube)
- Crear interfaz abstracta Shape con métodos virtuales - Refactorizar RotoBall → SphereShape (clase polimórfica) - Implementar CubeShape con triple rotación (X/Y/Z) - Distribución inteligente en cubo: vértices/centros/grid 3D - Cambiar controles: F=toggle, Q/W/E/R/T/Y/U/I=figuras, B=temas - Actualizar SimulationMode: ROTOBALL → SHAPE - Añadir enum ShapeType (8 figuras: Sphere/Cube/Helix/Torus/etc.) - Incluir source/shapes/*.cpp en CMakeLists.txt - Física compartida escalable entre todas las figuras - Roadmap: 6 figuras pendientes (Helix/Torus/Wave/Cylinder/Icosahedron/Atom) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
58
source/shapes/sphere_shape.cpp
Normal file
58
source/shapes/sphere_shape.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "sphere_shape.h"
|
||||
#include "../defines.h"
|
||||
#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;
|
||||
}
|
||||
Reference in New Issue
Block a user