#include "cylinder_shape.h" #include "../defines.h" #include void CylinderShape::generatePoints(int num_points, float screen_width, float screen_height) { num_points_ = num_points; radius_ = screen_height * CYLINDER_RADIUS_FACTOR; height_ = screen_height * CYLINDER_HEIGHT_FACTOR; // Las posiciones 3D se calculan en getPoint3D() usando ecuaciones paramétricas del cilindro } void CylinderShape::update(float delta_time, float screen_width, float screen_height) { // Recalcular dimensiones por si cambió resolución (F4) radius_ = screen_height * CYLINDER_RADIUS_FACTOR; height_ = screen_height * CYLINDER_HEIGHT_FACTOR; // Actualizar ángulo de rotación en eje Y angle_y_ += CYLINDER_ROTATION_SPEED_Y * delta_time; } void CylinderShape::getPoint3D(int index, float& x, float& y, float& z) const { // Distribuir puntos uniformemente en la superficie del cilindro // Calcular número de anillos (altura) y puntos por anillo (circunferencia) int num_rings = static_cast(sqrtf(static_cast(num_points_) * 0.5f)); if (num_rings < 2) num_rings = 2; int points_per_ring = num_points_ / num_rings; if (points_per_ring < 3) points_per_ring = 3; // Obtener parámetros u (ángulo) y v (altura) 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ámetro u (ángulo alrededor del cilindro): [0, 2π] float u = (static_cast(point_in_ring) / static_cast(points_per_ring)) * 2.0f * PI; // Parámetro v (altura normalizada): [-1, 1] float v = (static_cast(ring) / static_cast(num_rings - 1)) * 2.0f - 1.0f; if (num_rings == 1) v = 0.0f; // Ecuaciones paramétricas del cilindro // x = radius * cos(u) // y = height * v // z = radius * sin(u) float x_base = radius_ * cosf(u); float y_base = (height_ * 0.5f) * v; // Centrar verticalmente float z_base = radius_ * sinf(u); // 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; // Retornar coordenadas finales rotadas x = x_rot; y = y_base; z = z_rot; } float CylinderShape::getScaleFactor(float screen_height) const { // Factor de escala para física: proporcional a la dimensión mayor (altura) // Altura base = 120px (0.5 * 240px en resolución 320x240) const float BASE_HEIGHT = 120.0f; float current_height = screen_height * CYLINDER_HEIGHT_FACTOR; return current_height / BASE_HEIGHT; }