Skip to content

Commit

Permalink
rotor-effects: activate effects based on configured flight physic rea…
Browse files Browse the repository at this point in the history
…lism
  • Loading branch information
hsanjuan committed Nov 28, 2023
1 parent 65ea356 commit 6993198
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 15 deletions.
6 changes: 5 additions & 1 deletion src/sfm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

Expand Down
6 changes: 3 additions & 3 deletions src/sfmmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand All @@ -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. */
Expand All @@ -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. */
Expand Down
30 changes: 19 additions & 11 deletions src/sfmsimforce.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions src/sfmtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ typedef struct {
} SFMDirectionStruct;


typedef enum {
SFM_FLIGHT_PHYSICS_EASY,
SFM_FLIGHT_PHYSICS_MODERATE,
SFM_FLIGHT_PHYSICS_REALISTIC
} SFMFlightPhysicsLevel;



Expand Down
1 change: 1 addition & 0 deletions src/simmanage.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6993198

Please sign in to comment.