mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
move/name velocity constant, rename move_vec, simplify cam rotate_by()
Former-commit-id: 0835a9e91bd0133922f5d4e9731b9f6b6b547a0b
This commit is contained in:
parent
6f5f80f749
commit
33b8922aa4
@ -18,7 +18,7 @@ pub enum Error {
|
||||
|
||||
pub struct Input {
|
||||
// TODO: Use this type to manage client input
|
||||
pub move_vec: Vec2<f32>,
|
||||
pub move_dir: Vec2<f32>,
|
||||
}
|
||||
|
||||
pub struct Client {
|
||||
@ -101,23 +101,11 @@ impl Client {
|
||||
|
||||
// (step 1)
|
||||
if let Some(p) = self.player {
|
||||
let vel = input.move_vec;
|
||||
// TODO: remove this
|
||||
const PLAYER_VELOCITY: f32 = 100.0;
|
||||
|
||||
const MIN_LOOKING: f32 = 0.5;
|
||||
const LEANING_FAC: f32 = 0.05;
|
||||
|
||||
let dir = Vec3::from([
|
||||
// Rotation
|
||||
match vel.magnitude() > MIN_LOOKING {
|
||||
true => vel[0].atan2(vel[1]),
|
||||
_ => 0.0,
|
||||
},
|
||||
// Lean
|
||||
Vec2::new(vel[0], vel[1]).magnitude() * LEANING_FAC,
|
||||
]);
|
||||
|
||||
// TODO: Set acceleration instead and adjust dir calculations accordingly
|
||||
self.state.write_component(p, Vel(Vec3::from(vel)));
|
||||
// TODO: Set acceleration instead
|
||||
self.state.write_component(p, Vel(Vec3::from(input.move_dir * PLAYER_VELOCITY)));
|
||||
}
|
||||
|
||||
// Tick the client's LocalState (step 3)
|
||||
|
@ -20,6 +20,6 @@ impl<'a> System<'a> for MovementSys {
|
||||
fn run(&mut self, (mut positions, velocities, dt): Self::SystemData) {
|
||||
(&mut positions, &velocities)
|
||||
.join() // this can be parallelized with par_join()
|
||||
.for_each(|(pos, vel)| pos.0 += vel.0 * dt.0 as f32 * 100.0);
|
||||
.for_each(|(pos, vel)| pos.0 += vel.0 * dt.0 as f32);
|
||||
}
|
||||
}
|
||||
|
@ -53,13 +53,14 @@ impl Camera {
|
||||
|
||||
/// Rotate the camera about its focus by the given delta, limiting the input accordingly.
|
||||
pub fn rotate_by(&mut self, delta: Vec3<f32>) {
|
||||
self.ori += delta;
|
||||
// Wrap camera roll
|
||||
self.ori.x = self.ori.x % (2.0 * PI);
|
||||
// Wrap camera yaw
|
||||
self.ori.x = (self.ori.x + delta.x) % (2.0 * PI);
|
||||
// Clamp camera pitch to the vertical limits
|
||||
self.ori.y = self.ori.y
|
||||
self.ori.y = (self.ori.y + delta.y)
|
||||
.min(PI / 2.0)
|
||||
.max(-PI / 2.0);
|
||||
// Wrap camera roll
|
||||
self.ori.z = (self.ori.z + delta.z) % (2.0 * PI);
|
||||
}
|
||||
|
||||
/// Zoom the camera by the given delta, limiting the input accordingly.
|
||||
|
@ -58,9 +58,9 @@ impl SessionState {
|
||||
Vec2::new(ori[0].sin(), ori[0].cos()),
|
||||
);
|
||||
let dir_vec = self.key_state.dir_vec();
|
||||
let move_vec = unit_vecs.0 * dir_vec[0] + unit_vecs.1 * dir_vec[1];
|
||||
let move_dir = unit_vecs.0 * dir_vec[0] + unit_vecs.1 * dir_vec[1];
|
||||
|
||||
self.client.tick(client::Input { move_vec }, dt)?;
|
||||
self.client.tick(client::Input { move_dir }, dt)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user