Add the lookaround feature

main
_ 2020-03-11 03:49:10 +00:00
parent 754fd681c0
commit 51074df84c
1 changed files with 13 additions and 1 deletions

View File

@ -79,6 +79,9 @@ struct ControllerState {
analog_left_x: i16,
analog_left_y: i16,
analog_right_x: i16,
analog_right_y: i16,
trigger_left: i16,
trigger_right: i16,
}
@ -108,6 +111,8 @@ impl ControllerState {
],
analog_left_x: axis_or_zero (Axis::LeftX),
analog_left_y: axis_or_zero (Axis::LeftY),
analog_right_x: axis_or_zero (Axis::RightX),
analog_right_y: axis_or_zero (Axis::RightY),
trigger_left: axis_or_zero (Axis::TriggerLeft),
trigger_right: axis_or_zero (Axis::TriggerRight),
}
@ -223,6 +228,7 @@ struct FlightState {
airplane: Airplane,
spin_speed: i32,
arrows: Vec <Arrow>,
lookaround: EulerAngles,
}
impl Default for FlightState {
@ -235,6 +241,7 @@ impl Default for FlightState {
},
spin_speed: 0,
arrows: vec![],
lookaround: Default::default (),
}
}
}
@ -247,7 +254,10 @@ impl FlightState {
pub fn step (&mut self, controller: &ControllerState) {
self.spin_speed = controller.control_quat (&mut self.airplane.ori, self.spin_speed);
let throttle = 1.0 + (controller.trigger_right as f32 - controller.trigger_left as f32) / 32767.0;
self.lookaround.altitude = controller.analog_right_y as f32 * -90.0 / 32768.0;
self.lookaround.azimuth = controller.analog_right_x as f32 * 180.0 / 32768.0;
let throttle = 1.0 + (controller.trigger_right as f32 - controller.trigger_left as f32) / 32768.0;
let airplane = &mut self.airplane;
@ -830,6 +840,8 @@ impl GameGraphics {
PlayMode::FreeFlight => {
proj_mat *
Mat4::from_translation (Vec3::from ((0.0, -4.8, -32.0)) * airplane_scale) *
Mat4::from_rotation_x (state.flight.lookaround.altitude.to_radians ()) *
Mat4::from_rotation_y (state.flight.lookaround.azimuth.to_radians ()) *
Mat4::from_rotation_x (-90.0f32.to_radians ()) *
inverse_airplane
},