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 Aug 14, 2023
1 parent 3648508 commit 4290853
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 6 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
18 changes: 13 additions & 5 deletions src/sfmsimforce.c
Original file line number Diff line number Diff line change
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 4290853

Please sign in to comment.