lotus_script/axis.rs
1//! Logische Controller-Achsen und Force Feedback.
2//!
3//! Logical controller axes and force feedback.
4
5use lotus_script_sys::FfiObject;
6pub use lotus_shared::axis::*;
7
8/// Gibt den aktuellen Achsenwert zurück, im Bereich `0..=1`.
9/// Ohne Belegung oder vor dem ersten Messwert ist das [`AXIS_CENTER`] (0,5).
10///
11/// Returns the current axis value, in the range `0..=1`.
12/// Without a binding, or before the first sample, this is [`AXIS_CENTER`] (0.5).
13pub fn value(id: &str) -> f32 {
14 let id = FfiObject::new(&id);
15 unsafe { lotus_script_sys::axis::value(id.packed()) }
16}
17
18/// Setzt die Rückstellkraft der Achse.
19/// Koeffizient 0 schaltet die Feder aus. Werte außerhalb `0..=1` klemmt die Engine.
20///
21/// Sets the restoring force of the axis.
22/// A coefficient of 0 turns the spring off. The engine clamps values outside `0..=1`.
23pub fn center_force(id: &str, coefficient: f32, saturation: f32, offset: f32) {
24 let id = FfiObject::new(&id);
25 unsafe {
26 lotus_script_sys::axis::center_force(id.packed(), coefficient, saturation, offset);
27 }
28}
29
30/// Setzt die Reibung der Achse. 0 schaltet sie aus.
31///
32/// Sets the friction of the axis. 0 turns it off.
33pub fn friction(id: &str, coefficient: f32) {
34 let id = FfiObject::new(&id);
35 unsafe { lotus_script_sys::axis::friction(id.packed(), coefficient) }
36}
37
38/// Setzt die Schwingung der Achse. Magnitude 0 schaltet sie aus.
39///
40/// Sets the oscillation of the axis. A magnitude of 0 turns it off.
41pub fn vibration(id: &str, magnitude: f32, frequency_hz: f32) {
42 let id = FfiObject::new(&id);
43 unsafe { lotus_script_sys::axis::vibration(id.packed(), magnitude, frequency_hz) }
44}
45
46/// Registriert Achsen bei der Engine.
47/// Aufruf aus [`crate::Script::init`] oder am Anfang von [`crate::Script::actions`].
48/// [`crate::script`] ruft das nicht auf, bestehende Addon-Scripts bleiben unverändert.
49///
50/// Registers axes with the engine.
51/// Call this from [`crate::Script::init`] or at the start of [`crate::Script::actions`].
52/// [`crate::script`] does not call it, so existing addon scripts stay unchanged.
53pub fn register_many(axes: &[RegisterAxis]) {
54 for axis in axes {
55 let axis = FfiObject::new(&axis);
56 unsafe {
57 lotus_script_sys::axis::register(axis.packed());
58 }
59 }
60}