Expand description
Force feedback module.
To use force feedback, you have to create one or more Effect
s. Each
Effect
contains one or more BasicEffect
s and parameters that
describe effect’s source, like it’s position, gain or used
DistanceModel
. Final strength of effect is based on saturating sum
(to u16::MAX
) of all base effects and time from the start of playback, attenuation from
distance between effect source and listener (represented by gamepad) and effect’s gain.
See also Gilrs::set_listener_position()
and Gamepad::is_ff_supported()
.
§Example
use gilrs::Gilrs;
use gilrs::ff::{EffectBuilder, Replay, BaseEffect, BaseEffectType, Ticks};
let mut gilrs = Gilrs::new().unwrap();
let support_ff = gilrs
.gamepads()
.filter_map(|(id, gp)| if gp.is_ff_supported() { Some(id) } else { None })
.collect::<Vec<_>>();
let duration = Ticks::from_ms(150);
let effect = EffectBuilder::new()
.add_effect(BaseEffect {
kind: BaseEffectType::Strong { magnitude: 60_000 },
scheduling: Replay { play_for: duration, with_delay: duration * 3, ..Default::default() },
envelope: Default::default(),
})
.add_effect(BaseEffect {
kind: BaseEffectType::Weak { magnitude: 60_000 },
scheduling: Replay { after: duration * 2, play_for: duration, with_delay: duration * 3 },
..Default::default()
})
.gamepads(&support_ff)
.finish(&mut gilrs).unwrap();
effect.play().unwrap();
See examples/ff_pos.rs
for
more advanced example.
Modules§
Structs§
- Basic building block used to create more complex force feedback effects.
- Handle to force feedback effect.
- Creates new
Effect
. - Envelope shaped attenuation(time) function.
- Defines scheduling of the basic force feedback effect.
- Represents duration.
Enums§
- Kind of
BaseEffect
. - Specifies how distance between effect source and listener attenuates effect.
- Error that can be returned when passing
DistanceModel
with invalid value. - Basic error type in force feedback module.
- Describes how long effect should be played.