timescaled input
This commit is contained in:
@@ -97,4 +97,5 @@ name = "look_vertical"
|
|||||||
touch_axis = "vertical"
|
touch_axis = "vertical"
|
||||||
|
|
||||||
[config]
|
[config]
|
||||||
line_height_px = 16
|
line_height_px = 16
|
||||||
|
mouse_speed = 0.01
|
||||||
@@ -143,14 +143,14 @@ impl Updatable for Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Rotation
|
// Rotation
|
||||||
self.x_look += input.get_axis("look_vertical") * delta_time * self.look_sensitivity;
|
self.x_look += input.get_axis_timescaled("look_vertical", delta_time) * self.look_sensitivity;
|
||||||
self.y_look += input.get_axis("look_horizontal") * delta_time * self.look_sensitivity;
|
self.y_look += input.get_axis_timescaled("look_horizontal", delta_time) * self.look_sensitivity;
|
||||||
let x_rot = Quaternion::from_angle_x(Deg(self.x_look));
|
let x_rot = Quaternion::from_angle_x(Deg(self.x_look));
|
||||||
let y_rot = Quaternion::from_angle_y(Deg(self.y_look));
|
let y_rot = Quaternion::from_angle_y(Deg(self.y_look));
|
||||||
self.camera.rotation = x_rot * y_rot;
|
self.camera.rotation = x_rot * y_rot;
|
||||||
|
|
||||||
// Movement
|
// Movement
|
||||||
let local_input = vec3(input.get_axis("move_right"), 0.0, -input.get_axis("move_forward")) * self.movement_speed * delta_time;
|
let local_input = vec3(input.get_axis_timescaled("move_right", delta_time), 0.0, -input.get_axis_timescaled("move_forward", delta_time)) * self.movement_speed;
|
||||||
|
|
||||||
if self.movement_mode == FirstPerson {
|
if self.movement_mode == FirstPerson {
|
||||||
let mut world_input = self.camera.local_to_world(local_input);
|
let mut world_input = self.camera.local_to_world(local_input);
|
||||||
|
|||||||
13
src/input.rs
13
src/input.rs
@@ -43,6 +43,7 @@ struct InputConfig {
|
|||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct InputConfigConfig {
|
struct InputConfigConfig {
|
||||||
line_height_px: f32,
|
line_height_px: f32,
|
||||||
|
mouse_speed: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -399,30 +400,30 @@ impl InputState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_axis(self: &Self, axis_code: &str) -> f32 {
|
pub fn get_axis_timescaled(self: &Self, axis_code: &str, delta_time: f32) -> 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().map(|item| {
|
axis.axis_inputs.iter().map(|item| {
|
||||||
match &item {
|
match &item {
|
||||||
AxisInput::Wheel(modifiers) => {
|
AxisInput::Wheel(modifiers) => {
|
||||||
if self.modifiers_are_pressed(modifiers) { self.analog_wheel_state } else { 0.0 }
|
if self.modifiers_are_pressed(modifiers) { self.analog_wheel_state * delta_time } else { 0.0 }
|
||||||
},
|
},
|
||||||
AxisInput::MouseMove(direction, modifiers) => {
|
AxisInput::MouseMove(direction, modifiers) => {
|
||||||
if self.modifiers_are_pressed(modifiers) {
|
if self.modifiers_are_pressed(modifiers) {
|
||||||
match direction {
|
match direction {
|
||||||
MouseMoveDirection::X => self.mouse_delta_x as f32,
|
MouseMoveDirection::X => self.mouse_delta_x as f32 * self.config.mouse_speed,
|
||||||
MouseMoveDirection::Y => self.mouse_delta_y as f32,
|
MouseMoveDirection::Y => self.mouse_delta_y as f32 * self.config.mouse_speed,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
0.0
|
0.0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AxisInput::Digital(positive_button, negative_button) => {
|
AxisInput::Digital(positive_button, negative_button) => {
|
||||||
self.virtual_button_to_float(positive_button) - self.virtual_button_to_float(negative_button)
|
(self.virtual_button_to_float(positive_button) - self.virtual_button_to_float(negative_button)) * delta_time
|
||||||
},
|
},
|
||||||
AxisInput::Controller(controller_input) => {
|
AxisInput::Controller(controller_input) => {
|
||||||
self.controller_input.gamepads()
|
self.controller_input.gamepads()
|
||||||
.map(|(_id, gamepad)| gamepad.value(controller_input.axis))
|
.map(|(_id, gamepad)| gamepad.value(controller_input.axis))
|
||||||
.fold(0.0, fold_axis_value)
|
.fold(0.0, fold_axis_value) * delta_time
|
||||||
},
|
},
|
||||||
&AxisInput::Touch(touch_axis) => {
|
&AxisInput::Touch(touch_axis) => {
|
||||||
match touch_axis {
|
match touch_axis {
|
||||||
|
|||||||
Reference in New Issue
Block a user