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. Koeffizient und Sättigung übernimmt die Engine
20/// unbeschränkt, multipliziert sie mit der Geräte-Intensität und klemmt erst danach auf `0..=1`.
21/// `offset` verschiebt die Federmitte und wird danach auf `-1..=1` geklemmt; `0` lässt sie unverändert.
22///
23/// Sets the restoring force of the axis.
24/// A coefficient of 0 turns the spring off. The engine takes coefficient and saturation
25/// unrestricted, multiplies them by the device intensity, and only then clamps to `0..=1`.
26/// `offset` shifts the spring center and is then clamped to `-1..=1`; `0` leaves it unchanged.
27pub fn center_force(id: &str, coefficient: f32, saturation: f32, offset: f32) {
28 let id = FfiObject::new(&id);
29 unsafe {
30 lotus_script_sys::axis::center_force(id.packed(), coefficient, saturation, offset);
31 }
32}
33
34/// Setzt die Reibung der Achse. 0 schaltet sie aus.
35/// Die Engine übernimmt den Koeffizienten unbeschränkt, multipliziert mit der Geräte-Intensität
36/// und klemmt erst danach auf `0..=1`.
37///
38/// Sets the friction of the axis. 0 turns it off.
39/// The engine takes the coefficient unrestricted, multiplies by the device intensity,
40/// and only then clamps to `0..=1`.
41pub fn friction(id: &str, coefficient: f32) {
42 let id = FfiObject::new(&id);
43 unsafe { lotus_script_sys::axis::friction(id.packed(), coefficient) }
44}
45
46/// Setzt die Schwingung der Achse. Magnitude 0 schaltet sie aus.
47/// Die Stärke übernimmt die Engine unbeschränkt, multipliziert mit der Geräte-Intensität
48/// und klemmt erst danach auf `0..=1`.
49///
50/// Sets the oscillation of the axis. A magnitude of 0 turns it off.
51/// The engine takes the strength unrestricted, multiplies by the device intensity,
52/// and only then clamps to `0..=1`.
53pub fn vibration(id: &str, magnitude: f32, frequency_hz: f32) {
54 let id = FfiObject::new(&id);
55 unsafe { lotus_script_sys::axis::vibration(id.packed(), magnitude, frequency_hz) }
56}
57
58/// Registriert Achsen bei der Engine.
59/// Aufruf aus [`crate::Script::init`] oder am Anfang von [`crate::Script::actions`].
60/// [`crate::script`] ruft das nicht auf, bestehende Addon-Scripts bleiben unverändert.
61///
62/// Registers axes with the engine.
63/// Call this from [`crate::Script::init`] or at the start of [`crate::Script::actions`].
64/// [`crate::script`] does not call it, so existing addon scripts stay unchanged.
65pub fn register_many(axes: &[RegisterAxis]) {
66 for axis in axes {
67 let axis = FfiObject::new(&axis);
68 unsafe {
69 lotus_script_sys::axis::register(axis.packed());
70 }
71 }
72}