From 42908537596d8fa603d0233d11e7bbf03aefffd6 Mon Sep 17 00:00:00 2001 From: Hector Sanjuan Date: Mon, 14 Aug 2023 15:17:38 +0200 Subject: [PATCH] rotor-effects: activate effects based on configured flight physic realism --- src/sfm.h | 6 +++++- src/sfmsimforce.c | 18 +++++++++++++----- src/sfmtypes.h | 5 +++++ src/simmanage.c | 1 + 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/src/sfm.h b/src/sfm.h index c640f60..3966ec0 100644 --- a/src/sfm.h +++ b/src/sfm.h @@ -73,7 +73,11 @@ typedef struct { SFMPositionStruct actual_wind_vector; /* In meters per Cycle */ unsigned long wind_flags; SFMBoolean wind_enabled; - /* Callbacks, typical inputs are; realm pointer, + + /* Realism setting */ + SFMFlightPhysicsLevel flight_physics_level; + + /* Callbacks, typical inputs are; realm pointer, * model pointer, client data */ diff --git a/src/sfmsimforce.c b/src/sfmsimforce.c index 749ab25..4ba12f9 100644 --- a/src/sfmsimforce.c +++ b/src/sfmsimforce.c @@ -1532,7 +1532,8 @@ int SFMForceApplyArtificial( * Effect starts at a rotor height of 1.25 rotor diameter. * http://www.copters.com/aero/ground_effect.html */ - if(flags & SFMFlagRotorDiameter) + if(flags & SFMFlagRotorDiameter && + realm->flight_physics_level >= SFM_FLIGHT_PHYSICS_MODERATE) { // Twin-rotor aircrafts note: // - Coaxial are assumed to experience normal IGE since its a single @@ -1596,6 +1597,7 @@ int SFMForceApplyArtificial( */ if (flags & SFMFlagSingleMainRotor && // does not affect twin as they compensate. + realm->flight_physics_level >= SFM_FLIGHT_PHYSICS_REALISTIC && !model->landed_state && airspeed_rotor_2d > 0 ) { @@ -1626,12 +1628,17 @@ int SFMForceApplyArtificial( * * https://en.wikipedia.org/wiki/Translational_lift */ + + // ETL Thrust penalty // Goes from 1 (full penalty) to 0 when it reaches SFMETLSpeed // Square progression so that it goes a bit slower close to 0. - double etl_thrust_coeff = 1 - POW(CLIP(airspeed_rotor_2d / SFMETLSpeed, 0, 1),2); - thrust_output = (1 - 0.25 * etl_thrust_coeff) * thrust_output; - - if (!model->landed_state && + if (realm->flight_physics_level >= SFM_FLIGHT_PHYSICS_MODERATE) { + double etl_thrust_coeff = 1 - POW(CLIP(airspeed_rotor_2d / SFMETLSpeed, 0, 1),2); + thrust_output = (1 - 0.25 * etl_thrust_coeff) * thrust_output; + } + // ETL pitch + if (realm->flight_physics_level >= SFM_FLIGHT_PHYSICS_REALISTIC && + !model->landed_state && airspeed_rotor_2d > 0 ) { // Similar to TF, we add some pitch/bank changes while @@ -1659,6 +1666,7 @@ int SFMForceApplyArtificial( */ if(flags & SFMFlagSingleMainRotor && // does not affect twin rotors + realm->flight_physics_level >= SFM_FLIGHT_PHYSICS_REALISTIC && !model->landed_state ) { // torque_coeff: 1 at 0-speed, 0 at SFMETLEnd and negative diff --git a/src/sfmtypes.h b/src/sfmtypes.h index b4d04e3..27c26a4 100644 --- a/src/sfmtypes.h +++ b/src/sfmtypes.h @@ -79,6 +79,11 @@ typedef struct { } SFMDirectionStruct; +typedef enum { + SFM_FLIGHT_PHYSICS_EASY, + SFM_FLIGHT_PHYSICS_MODERATE, + SFM_FLIGHT_PHYSICS_REALISTIC +} SFMFlightPhysicsLevel; diff --git a/src/simmanage.c b/src/simmanage.c index 47323f5..8a2cb5e 100644 --- a/src/simmanage.c +++ b/src/simmanage.c @@ -690,6 +690,7 @@ int SARSimUpdateSceneObjects( if(scene->realm != NULL) { scene->realm->wind_enabled = core_ptr->option.wind; + scene->realm->flight_physics_level = (SFMFlightPhysicsLevel)(core_ptr->option.flight_physics_level); /* Handle by object type */ switch(obj_ptr->type)