fix(debris): rotación visual decae con fricción + modulada por size_factor
This commit is contained in:
@@ -40,7 +40,8 @@ namespace Defaults::Physics {
|
|||||||
// Herència de velocity angular (trayectorias curvas)
|
// Herència de velocity angular (trayectorias curvas)
|
||||||
constexpr float FACTOR_HERENCIA_MIN = 0.7F; // Mínimo 70% del drotacio heredat
|
constexpr float FACTOR_HERENCIA_MIN = 0.7F; // Mínimo 70% del drotacio heredat
|
||||||
constexpr float FACTOR_HERENCIA_MAX = 1.0F; // Màxim 100% del drotacio heredat
|
constexpr float FACTOR_HERENCIA_MAX = 1.0F; // Màxim 100% del drotacio heredat
|
||||||
constexpr float FRICCIO_ANGULAR = 0.5F; // Desacceleració angular (rad/s²)
|
constexpr float FRICCIO_ANGULAR = 0.5F; // Desacceleració de la rotació de TRAJECTÒRIA (rad/s²)
|
||||||
|
constexpr float FRICCIO_VISUAL = 0.1F; // Desacceleració de la rotació VISUAL (més suau)
|
||||||
|
|
||||||
// Velocity heredada de la nau a l'explosió (80% del feel original).
|
// Velocity heredada de la nau a l'explosió (80% del feel original).
|
||||||
constexpr float SHIP_VELOCITY_INHERITANCE = 0.8F;
|
constexpr float SHIP_VELOCITY_INHERITANCE = 0.8F;
|
||||||
|
|||||||
@@ -256,13 +256,24 @@ namespace Effects {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Rota el vector velocity (trajectòria corba) i aplica fricció angular.
|
// Aplica fricció a una velocity angular (genèric per a trajectòria i visual).
|
||||||
static void applyAngularDynamics(Debris& debris, float delta_time) {
|
static void decayAngular(float& vel, float friction, float delta_time) {
|
||||||
if (std::abs(debris.velocitat_rot) <= 0.01F) {
|
if (std::abs(vel) <= 0.01F) {
|
||||||
|
vel = 0.0F;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const float SIGN = (vel > 0) ? 1.0F : -1.0F;
|
||||||
|
vel -= SIGN * friction * delta_time;
|
||||||
|
if ((vel > 0) != (SIGN > 0)) {
|
||||||
|
vel = 0.0F;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Rotar vector de velocity amb matriu 2D
|
// Rota el vector velocity (trajectòria corba) i aplica fricció a ambdues
|
||||||
|
// velocitats angulars (trajectòria i visual).
|
||||||
|
static void applyAngularDynamics(Debris& debris, float delta_time) {
|
||||||
|
// Rotar vector de velocity amb matriu 2D (només si encara gira la trajectòria)
|
||||||
|
if (std::abs(debris.velocitat_rot) > 0.01F) {
|
||||||
const float DANGLE = debris.velocitat_rot * delta_time;
|
const float DANGLE = debris.velocitat_rot * delta_time;
|
||||||
const float VX = debris.velocity.x;
|
const float VX = debris.velocity.x;
|
||||||
const float VY = debris.velocity.y;
|
const float VY = debris.velocity.y;
|
||||||
@@ -270,14 +281,15 @@ namespace Effects {
|
|||||||
const float SIN_A = std::sin(DANGLE);
|
const float SIN_A = std::sin(DANGLE);
|
||||||
debris.velocity.x = (VX * COS_A) - (VY * SIN_A);
|
debris.velocity.x = (VX * COS_A) - (VY * SIN_A);
|
||||||
debris.velocity.y = (VX * SIN_A) + (VY * COS_A);
|
debris.velocity.y = (VX * SIN_A) + (VY * COS_A);
|
||||||
|
|
||||||
// Fricció angular (desacceleració gradual)
|
|
||||||
const float SIGN = (debris.velocitat_rot > 0) ? 1.0F : -1.0F;
|
|
||||||
const float REDUCCION = Defaults::Physics::Debris::FRICCIO_ANGULAR * delta_time;
|
|
||||||
debris.velocitat_rot -= SIGN * REDUCCION;
|
|
||||||
if ((debris.velocitat_rot > 0) != (SIGN > 0)) {
|
|
||||||
debris.velocitat_rot = 0.0F;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Decay independent de les dues velocitats angulars.
|
||||||
|
decayAngular(debris.velocitat_rot,
|
||||||
|
Defaults::Physics::Debris::FRICCIO_ANGULAR,
|
||||||
|
delta_time);
|
||||||
|
decayAngular(debris.velocitat_rot_visual,
|
||||||
|
Defaults::Physics::Debris::FRICCIO_VISUAL,
|
||||||
|
delta_time);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DebrisManager::update(float delta_time) {
|
void DebrisManager::update(float delta_time) {
|
||||||
@@ -299,8 +311,11 @@ namespace Effects {
|
|||||||
centro.x += debris.velocity.x * delta_time;
|
centro.x += debris.velocity.x * delta_time;
|
||||||
centro.y += debris.velocity.y * delta_time;
|
centro.y += debris.velocity.y * delta_time;
|
||||||
|
|
||||||
// Rotació visual del segment
|
// Rotació visual del segment. Modulada per size_factor: durant
|
||||||
debris.angle_rotacio += debris.velocitat_rot_visual * delta_time;
|
// INTACTE (size=1) no afecta, però quan el segment mengua la
|
||||||
|
// rotació també s'apaga, evitant l'efecte "hèlix d'avió" quan
|
||||||
|
// el segment es fa molt petit.
|
||||||
|
debris.angle_rotacio += debris.velocitat_rot_visual * debris.size_factor * delta_time;
|
||||||
|
|
||||||
// Mida actual = size_factor (1.0 intacte, decreix durant MENGUANT)
|
// Mida actual = size_factor (1.0 intacte, decreix durant MENGUANT)
|
||||||
const float SHRINK_FACTOR = std::max(0.0F, debris.size_factor);
|
const float SHRINK_FACTOR = std::max(0.0F, debris.size_factor);
|
||||||
|
|||||||
Reference in New Issue
Block a user