2023-05-22 16:18:35 +00:00
|
|
|
use cgmath::{Point3, Deg, Vector3, Rad, InnerSpace};
|
|
|
|
use crate::input::Input;
|
2023-05-20 17:33:25 +00:00
|
|
|
|
|
|
|
pub struct Player {
|
|
|
|
pub position: Point3<f32>,
|
2023-05-22 16:18:35 +00:00
|
|
|
pub rot_x: Deg<f32>,
|
2023-05-20 17:33:25 +00:00
|
|
|
|
|
|
|
pub buffer: wgpu::Buffer,
|
2023-05-22 16:18:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Player {
|
|
|
|
pub fn update_pos(&mut self, input: &Input, dt: f32) {
|
|
|
|
let (sin, cos) = Rad::from(self.rot_x).0.sin_cos();
|
|
|
|
let forward = Vector3::new(cos, 0.0, sin).normalize();
|
|
|
|
let right = Vector3::new(-sin, 0.0, cos).normalize();
|
|
|
|
self.position += forward * (input.amount_forward - input.amount_backward) * (input.speed * dt);
|
|
|
|
self.position += right * (input.amount_right - input.amount_left) * (input.speed * dt);
|
|
|
|
|
|
|
|
self.position.y += (input.amount_up - input.amount_down) * (input.speed * dt);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
pub fn update_rot(&mut self, input: &Input, sf: f32) {
|
|
|
|
// doesn't need dt because the input is not continuous.
|
|
|
|
let (dx, _) = input.mouse_moved;
|
|
|
|
self.rot_x += Deg((dx / input.dots_per_deg) * sf);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
2023-05-20 17:33:25 +00:00
|
|
|
}
|