Add the lookaround feature
parent
754fd681c0
commit
51074df84c
|
@ -79,6 +79,9 @@ struct ControllerState {
|
||||||
analog_left_x: i16,
|
analog_left_x: i16,
|
||||||
analog_left_y: i16,
|
analog_left_y: i16,
|
||||||
|
|
||||||
|
analog_right_x: i16,
|
||||||
|
analog_right_y: i16,
|
||||||
|
|
||||||
trigger_left: i16,
|
trigger_left: i16,
|
||||||
trigger_right: i16,
|
trigger_right: i16,
|
||||||
}
|
}
|
||||||
|
@ -108,6 +111,8 @@ impl ControllerState {
|
||||||
],
|
],
|
||||||
analog_left_x: axis_or_zero (Axis::LeftX),
|
analog_left_x: axis_or_zero (Axis::LeftX),
|
||||||
analog_left_y: axis_or_zero (Axis::LeftY),
|
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_left: axis_or_zero (Axis::TriggerLeft),
|
||||||
trigger_right: axis_or_zero (Axis::TriggerRight),
|
trigger_right: axis_or_zero (Axis::TriggerRight),
|
||||||
}
|
}
|
||||||
|
@ -223,6 +228,7 @@ struct FlightState {
|
||||||
airplane: Airplane,
|
airplane: Airplane,
|
||||||
spin_speed: i32,
|
spin_speed: i32,
|
||||||
arrows: Vec <Arrow>,
|
arrows: Vec <Arrow>,
|
||||||
|
lookaround: EulerAngles,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for FlightState {
|
impl Default for FlightState {
|
||||||
|
@ -235,6 +241,7 @@ impl Default for FlightState {
|
||||||
},
|
},
|
||||||
spin_speed: 0,
|
spin_speed: 0,
|
||||||
arrows: vec![],
|
arrows: vec![],
|
||||||
|
lookaround: Default::default (),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,7 +254,10 @@ impl FlightState {
|
||||||
pub fn step (&mut self, controller: &ControllerState) {
|
pub fn step (&mut self, controller: &ControllerState) {
|
||||||
self.spin_speed = controller.control_quat (&mut self.airplane.ori, self.spin_speed);
|
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;
|
let airplane = &mut self.airplane;
|
||||||
|
|
||||||
|
@ -830,6 +840,8 @@ impl GameGraphics {
|
||||||
PlayMode::FreeFlight => {
|
PlayMode::FreeFlight => {
|
||||||
proj_mat *
|
proj_mat *
|
||||||
Mat4::from_translation (Vec3::from ((0.0, -4.8, -32.0)) * airplane_scale) *
|
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 ()) *
|
Mat4::from_rotation_x (-90.0f32.to_radians ()) *
|
||||||
inverse_airplane
|
inverse_airplane
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue