Add strafing

This commit is contained in:
Patrick Walton 2019-01-17 08:45:23 -08:00
parent 554586c5bf
commit f3e0d2777a
2 changed files with 25 additions and 0 deletions

View File

@ -138,10 +138,20 @@ fn main() {
Event::KeyDown { keycode: Some(Keycode::S), .. } => {
camera_velocity.set_z(CAMERA_VELOCITY)
}
Event::KeyDown { keycode: Some(Keycode::A), .. } => {
camera_velocity.set_x(-CAMERA_VELOCITY)
}
Event::KeyDown { keycode: Some(Keycode::D), .. } => {
camera_velocity.set_x(CAMERA_VELOCITY)
}
Event::KeyUp { keycode: Some(Keycode::W), .. } |
Event::KeyUp { keycode: Some(Keycode::S), .. } => {
camera_velocity.set_z(0.0);
}
Event::KeyUp { keycode: Some(Keycode::A), .. } |
Event::KeyUp { keycode: Some(Keycode::D), .. } => {
camera_velocity.set_x(0.0);
}
_ => {}
}
}

View File

@ -140,11 +140,26 @@ impl Point4DF32 {
self.0[3]
}
#[inline]
pub fn set_x(&mut self, x: f32) {
self.0[0] = x
}
#[inline]
pub fn set_y(&mut self, y: f32) {
self.0[1] = y
}
#[inline]
pub fn set_z(&mut self, z: f32) {
self.0[2] = z
}
#[inline]
pub fn set_w(&mut self, w: f32) {
self.0[3] = w
}
#[inline]
pub fn perspective_divide(self) -> Point4DF32 {
self * Point4DF32::splat(1.0 / self.w())