fix: multiple axis inputs
This commit is contained in:
@@ -7,10 +7,22 @@ name = "RELOAD_SHADERS"
|
|||||||
scan_code = 19
|
scan_code = 19
|
||||||
ctrl = true
|
ctrl = true
|
||||||
|
|
||||||
|
[[button]]
|
||||||
|
name = "FORWARD"
|
||||||
|
scan_code = 17
|
||||||
|
|
||||||
|
[[button]]
|
||||||
|
name = "BACK"
|
||||||
|
scan_code = 31
|
||||||
|
|
||||||
|
[[axis]]
|
||||||
|
name = "FORWARD_AXIS"
|
||||||
|
positive_button = "FORWARD"
|
||||||
|
negative_button = "BACK"
|
||||||
|
|
||||||
[[axis]]
|
[[axis]]
|
||||||
name = "FORWARD_AXIS"
|
name = "FORWARD_AXIS"
|
||||||
mouse_wheel = true
|
mouse_wheel = true
|
||||||
ctrl = true
|
|
||||||
|
|
||||||
[config]
|
[config]
|
||||||
line_height_px = 16
|
line_height_px = 16
|
||||||
11
src/input.rs
11
src/input.rs
@@ -193,17 +193,12 @@ impl InputState {
|
|||||||
|
|
||||||
pub fn get_axis(self: &Self, axis_code: &str) -> f32 {
|
pub fn get_axis(self: &Self, axis_code: &str) -> f32 {
|
||||||
if let Some(axis) = self.virtual_axes.get(axis_code) {
|
if let Some(axis) = self.virtual_axes.get(axis_code) {
|
||||||
axis.axis_inputs.iter().fold(0.0, |fold, item| {
|
axis.axis_inputs.iter().map(|item| {
|
||||||
let val = match item {
|
match item {
|
||||||
AxisInput::Wheel(modifiers) => if self.modifiers_are_pressed(*modifiers) { self.analog_wheel_state } else { 0.0 },
|
AxisInput::Wheel(modifiers) => if self.modifiers_are_pressed(*modifiers) { self.analog_wheel_state } else { 0.0 },
|
||||||
AxisInput::Digital(positive_button, negative_button) => self.virtual_button_to_float(positive_button) - self.virtual_button_to_float(negative_button),
|
AxisInput::Digital(positive_button, negative_button) => self.virtual_button_to_float(positive_button) - self.virtual_button_to_float(negative_button),
|
||||||
};
|
|
||||||
if f32::abs(val) > fold {
|
|
||||||
val
|
|
||||||
} else {
|
|
||||||
fold
|
|
||||||
}
|
}
|
||||||
})
|
}).fold(0.0, |fold, it| if f32::abs(it) > f32::abs(fold) { it } else { fold })
|
||||||
} else {
|
} else {
|
||||||
assert!(false, format!("Axis {:?} not found!", axis_code));
|
assert!(false, format!("Axis {:?} not found!", axis_code));
|
||||||
0.0
|
0.0
|
||||||
|
|||||||
10
src/main.rs
10
src/main.rs
@@ -17,6 +17,10 @@ struct TestGame {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Game for TestGame {
|
impl Game for TestGame {
|
||||||
|
fn validation_layers_enabled(self: &Self) -> bool {
|
||||||
|
self.log_config.vulkan_validation_layers
|
||||||
|
}
|
||||||
|
|
||||||
fn update(self: &mut Self, game_data: &mut GameData) {
|
fn update(self: &mut Self, game_data: &mut GameData) {
|
||||||
// User interaction
|
// User interaction
|
||||||
if self.input.button_just_released("QUIT") {
|
if self.input.button_just_released("QUIT") {
|
||||||
@@ -44,7 +48,7 @@ impl Game for TestGame {
|
|||||||
Rad::from(Deg(45.0)),
|
Rad::from(Deg(45.0)),
|
||||||
game_data.dimensions[0] as f32 / game_data.dimensions[1] as f32,
|
game_data.dimensions[0] as f32 / game_data.dimensions[1] as f32,
|
||||||
0.1,
|
0.1,
|
||||||
10.0
|
100.0
|
||||||
);
|
);
|
||||||
|
|
||||||
proj.y.y *= -1.0;
|
proj.y.y *= -1.0;
|
||||||
@@ -99,10 +103,6 @@ impl Game for TestGame {
|
|||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validation_layers_enabled(self: &Self) -> bool {
|
|
||||||
self.log_config.vulkan_validation_layers
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|||||||
Reference in New Issue
Block a user