aboutsummaryrefslogtreecommitdiff
path: root/stockton-contrib
diff options
context:
space:
mode:
authortcmal <me@aria.rip>2024-08-25 17:44:22 +0100
committertcmal <me@aria.rip>2024-08-25 17:44:22 +0100
commitcde43cfd5c285dc213895cebc305d9ba7f094d1a (patch)
tree426b3179b2367d8823dd6ed537ba4548214f8cd6 /stockton-contrib
parent1a0ac4464c2053e8b08e867c3abb77b89d951d9c (diff)
feat(contrib): add mouse input to flycam controls
Diffstat (limited to 'stockton-contrib')
-rw-r--r--stockton-contrib/src/flycam.rs31
1 files changed, 22 insertions, 9 deletions
diff --git a/stockton-contrib/src/flycam.rs b/stockton-contrib/src/flycam.rs
index 7b82c4f..093f75a 100644
--- a/stockton-contrib/src/flycam.rs
+++ b/stockton-contrib/src/flycam.rs
@@ -15,7 +15,9 @@
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
-use stockton_input::{Axis, InputManager};
+use std::f32::consts::PI;
+
+use stockton_input::{Axis, InputManager, Mouse};
use stockton_types::components::Transform;
use stockton_types::Vector3;
@@ -29,27 +31,38 @@ pub trait FlycamInput {
pub struct FlycamControlled {
pub speed: f32,
+ pub sensitivity: f32,
+}
+
+impl FlycamControlled {
+ pub fn new(speed: f32, pixels_per_360: f32) -> Self {
+ FlycamControlled {
+ speed,
+ sensitivity: (2.0 * PI) / pixels_per_360,
+ }
+ }
}
#[system(for_each)]
pub fn flycam_move<T>(
#[resource] manager: &T,
#[resource] timing: &Timing,
+ #[resource] mouse: &Mouse,
transform: &mut Transform,
flycam: &FlycamControlled,
) where
T: 'static + InputManager,
T::Inputs: FlycamInput,
{
- // TODO: Deal with looking around
-
let inputs = manager.get_inputs();
- let speed = flycam.speed;
- let impulse = Vector3::new(
- **inputs.get_x_axis() as f32 * speed * timing.delta_time,
- **inputs.get_y_axis() as f32 * speed * timing.delta_time,
- **inputs.get_z_axis() as f32 * speed * timing.delta_time,
+ let delta = Vector3::new(
+ **inputs.get_x_axis() as f32 * flycam.speed * timing.delta_time,
+ **inputs.get_y_axis() as f32 * flycam.speed * timing.delta_time,
+ **inputs.get_z_axis() as f32 * flycam.speed * timing.delta_time,
);
- transform.position += impulse;
+ transform.translate(delta);
+
+ let rotation = mouse.delta * flycam.sensitivity;
+ transform.rotate(Vector3::new(-rotation.y, rotation.x, 0.0));
}