From 6993198d5104a99e29b787adc0420354d21c98ff 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/sfmmodel.h | 6 +++--- src/sfmsimforce.c | 30 +++++++++++++++++++----------- src/sfmtypes.h | 5 +++++ src/simmanage.c | 1 + 5 files changed, 33 insertions(+), 15 deletions(-) diff --git a/src/sfm.h b/src/sfm.h index c640f60..eecbbf0 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/sfmmodel.h b/src/sfmmodel.h index 03e42fd..5befe98 100644 --- a/src/sfmmodel.h +++ b/src/sfmmodel.h @@ -130,7 +130,7 @@ typedef struct { */ SFMFlags flags; - int type; /* One of SFMFlightModel*. */ + int type; /* One of SFMFlightModel*. */ SFMPositionStruct position; /* Meters. */ SFMDirectionStruct direction; /* Radians. */ SFMPositionStruct velocity_vector; /* Meters/cycle. */ @@ -148,7 +148,7 @@ typedef struct { SFMPositionStruct accel_responsiveness; double ground_elevation_msl; /* Meters. */ double service_ceiling; /* Meters. */ - double length; /* Meters */ + double length; /* Meters */ double wingspan; /* Meters */ double rotor_diameter; /* Meters */ double belly_height; /* Undercarrage to center, meters. */ @@ -173,7 +173,7 @@ typedef struct { double pitch_control_coeff; /* -1.0 to 1.0. */ double bank_control_coeff; /* -1.0 to 1.0. */ double elevator_trim_coeff; /* -1.0 to 1.0. */ - double throttle_coeff; /* 0.0 to 1.0. */ + double throttle_coeff; /* 0.0 to 1.0. */ SFMBoolean after_burner_state; double after_burner_power_coeff; /* Times engine power. */ double engine_power; /* In kg * m / cycle^2. */ diff --git a/src/sfmsimforce.c b/src/sfmsimforce.c index 749ab25..2e903ff 100644 --- a/src/sfmsimforce.c +++ b/src/sfmsimforce.c @@ -785,11 +785,11 @@ int SFMForceApplyNatural( * It improves upon the original code doing this, which * has been removed: - if(!model->landed_state) - dir->heading = SFMSanitizeRadians( - dir->heading + (sin_pitch * sin_bank * - (0.2 * PI) * - time_compensation * time_compression) + if(!model->landed_state) + dir->heading = SFMSanitizeRadians( + dir->heading + (sin_pitch * sin_bank * + (0.2 * PI) * + time_compensation * time_compression) * * When the helicopter pitches forward and banks, the @@ -814,7 +814,7 @@ int SFMForceApplyNatural( * We have however reduced the PI multiplier to 0.15 * instead of 0.2. */ - + // Originally this was part of ArtificialForces, but // now it is here (i don't remember the reason). It is a // thrust-independent effect after all. @@ -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)