limitada la velocitat angular dels debris i transformada en velocitat lineal tangencial
This commit is contained in:
@@ -112,20 +112,53 @@ void DebrisManager::explotar(const std::shared_ptr<Graphics::Shape>& shape,
|
||||
debris->velocitat.y = direccio.y * speed + velocitat_objecte.y;
|
||||
debris->acceleracio = Defaults::Physics::Debris::ACCELERACIO;
|
||||
|
||||
// 6. Herència de velocitat angular
|
||||
// 6. Herència de velocitat angular amb cap + conversió d'excés
|
||||
|
||||
// 6a. Rotació de TRAYECTORIA (sempre hereda si velocitat_angular > 0)
|
||||
// 6a. Rotació de TRAYECTORIA amb cap + conversió tangencial
|
||||
if (std::abs(velocitat_angular) > 0.01f) {
|
||||
// FASE 1: Aplicar herència i variació (igual que abans)
|
||||
float factor_herencia =
|
||||
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN +
|
||||
(std::rand() / static_cast<float>(RAND_MAX)) *
|
||||
(Defaults::Physics::Debris::FACTOR_HERENCIA_MAX -
|
||||
Defaults::Physics::Debris::FACTOR_HERENCIA_MIN);
|
||||
debris->velocitat_rot = velocitat_angular * factor_herencia;
|
||||
|
||||
float velocitat_ang_heretada = velocitat_angular * factor_herencia;
|
||||
|
||||
float variacio =
|
||||
(std::rand() / static_cast<float>(RAND_MAX)) * 0.2f - 0.1f;
|
||||
debris->velocitat_rot *= (1.0f + variacio);
|
||||
velocitat_ang_heretada *= (1.0f + variacio);
|
||||
|
||||
// FASE 2: Aplicar cap i calcular excés
|
||||
constexpr float CAP = Defaults::Physics::Debris::VELOCITAT_ROT_MAX;
|
||||
float abs_ang = std::abs(velocitat_ang_heretada);
|
||||
float sign_ang = (velocitat_ang_heretada >= 0.0f) ? 1.0f : -1.0f;
|
||||
|
||||
if (abs_ang > CAP) {
|
||||
// Excés: convertir a velocitat tangencial
|
||||
float excess = abs_ang - CAP;
|
||||
|
||||
// Radi de la forma (enemics = 20 px)
|
||||
float radius = 20.0f;
|
||||
|
||||
// Velocitat tangencial = ω_excés × radi
|
||||
float v_tangential = excess * radius;
|
||||
|
||||
// Direcció tangencial: perpendicular a la radial (90° CCW)
|
||||
// Si direccio = (dx, dy), tangent = (-dy, dx)
|
||||
float tangent_x = -direccio.y;
|
||||
float tangent_y = direccio.x;
|
||||
|
||||
// Afegir velocitat tangencial (suma vectorial)
|
||||
debris->velocitat.x += tangent_x * v_tangential;
|
||||
debris->velocitat.y += tangent_y * v_tangential;
|
||||
|
||||
// Aplicar cap a velocitat angular (preservar signe)
|
||||
debris->velocitat_rot = sign_ang * CAP;
|
||||
} else {
|
||||
// Per sota del cap: comportament normal
|
||||
debris->velocitat_rot = velocitat_ang_heretada;
|
||||
}
|
||||
} else {
|
||||
debris->velocitat_rot = 0.0f; // Nave: sin curvas
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user