@@ -32,6 +32,22 @@ public enum Effect
3232 private float _gearChangeAmplitude = 0f ;
3333 private float _gearChangeTimer = 0f ;
3434
35+ private readonly float [ ] _frequency = [ 0f , 0f , 0f ] ;
36+ private readonly float [ ] _amplitude = [ 0f , 0f , 0f ] ;
37+ private readonly float [ ] _cycles = [ 0f , 0f , 0f ] ;
38+
39+ public void Initialize ( )
40+ {
41+ var app = App . Instance ;
42+
43+ if ( app != null )
44+ {
45+ app . Graph . SetLayerColors ( Graph . LayerIndex . ClutchPedalHaptics , 0f , 0f , 0.5f , 0f , 0f , 1f ) ;
46+ app . Graph . SetLayerColors ( Graph . LayerIndex . BrakePedalHaptics , 0.5f , 0f , 0f , 1f , 0f , 0f ) ;
47+ app . Graph . SetLayerColors ( Graph . LayerIndex . ThrottlePedalHaptics , 0f , 0.5f , 0f , 0f , 1f , 0f ) ;
48+ }
49+ }
50+
3551 public void Refresh ( )
3652 {
3753 var app = App . Instance ;
@@ -87,6 +103,23 @@ public static void SetMairaComboBoxItemsSource( MairaComboBox mairaComboBox )
87103 }
88104 }
89105
106+ public void UpdateGraph ( )
107+ {
108+ var app = App . Instance ;
109+
110+ if ( app != null )
111+ {
112+ for ( var i = 0 ; i < 3 ; i ++ )
113+ {
114+ _cycles [ i ] += _frequency [ i ] * MathF . Tau / 500f ;
115+
116+ var amplitude = MathF . Sin ( _cycles [ i ] ) * _amplitude [ i ] ;
117+
118+ app . Graph . UpdateLayer ( Graph . LayerIndex . ClutchPedalHaptics + i , amplitude , amplitude ) ;
119+ }
120+ }
121+ }
122+
90123 public void Update ( App app )
91124 {
92125 // update gear change effect timer
@@ -104,6 +137,18 @@ public void Update( App app )
104137 _hpr . VibratePedal ( HPR . Channel . Brake , HPR . State . Off , 0 , 0 ) ;
105138 _hpr . VibratePedal ( HPR . Channel . Throttle , HPR . State . Off , 0 , 0 ) ;
106139
140+ _frequency [ 0 ] = 0f ;
141+ _frequency [ 1 ] = 0f ;
142+ _frequency [ 2 ] = 0f ;
143+
144+ _amplitude [ 0 ] = 0f ;
145+ _amplitude [ 1 ] = 0f ;
146+ _amplitude [ 2 ] = 0f ;
147+
148+ _cycles [ 0 ] = 0f ;
149+ _cycles [ 1 ] = 0f ;
150+ _cycles [ 2 ] = 0f ;
151+
107152 return ;
108153 }
109154
@@ -122,13 +167,13 @@ public void Update( App app )
122167 {
123168 if ( app . Simulator . Gear == 0 )
124169 {
125- _gearChangeFrequency = settings . PedalsShiftIntoNeutralFrequency ;
170+ _gearChangeFrequency = Misc . Lerp ( settings . PedalsMinimumFrequency , settings . PedalsMaximumFrequency , settings . PedalsShiftIntoNeutralFrequency ) ;
126171 _gearChangeAmplitude = settings . PedalsShiftIntoNeutralAmplitude ;
127172 _gearChangeTimer = settings . PedalsShiftIntoNeutralDuration ;
128173 }
129174 else
130175 {
131- _gearChangeFrequency = settings . PedalsShiftIntoGearFrequency ;
176+ _gearChangeFrequency = Misc . Lerp ( settings . PedalsMinimumFrequency , settings . PedalsMaximumFrequency , settings . PedalsShiftIntoGearFrequency ) ;
132177 _gearChangeAmplitude = settings . PedalsShiftIntoGearAmplitude ;
133178 _gearChangeTimer = settings . PedalsShiftIntoGearDuration ;
134179 }
@@ -175,11 +220,22 @@ public void Update( App app )
175220
176221 if ( effectActive )
177222 {
223+ amplitude *= MathF . Pow ( frequency / 50f , Misc . CurveToPower ( settings . PedalsNoiseDamper ) ) ;
224+
178225 _hpr . VibratePedal ( ( HPR . Channel ) i , HPR . State . On , frequency , amplitude * 100f ) ;
226+
227+ _frequency [ i ] = ( int ) ( Math . Clamp ( frequency , 1f , 50f ) ) ;
228+ _amplitude [ i ] = amplitude ;
179229 }
180230 else
181231 {
182232 _hpr . VibratePedal ( ( HPR . Channel ) i , HPR . State . Off , 0f , 0f ) ;
233+
234+ app . Graph . UpdateLayer ( Graph . LayerIndex . ClutchPedalHaptics + i , 0f , 0f ) ;
235+
236+ _frequency [ i ] = 0f ;
237+ _amplitude [ i ] = 0f ;
238+ _cycles [ i ] = 0f ;
183239 }
184240 }
185241 }
0 commit comments