diff --git a/airplane.iqm b/airplane.iqm index bc08835..fb5a60a 100644 Binary files a/airplane.iqm and b/airplane.iqm differ diff --git a/src/bin/pumpkin.rs b/src/bin/pumpkin.rs index b941831..dac8c43 100644 --- a/src/bin/pumpkin.rs +++ b/src/bin/pumpkin.rs @@ -108,6 +108,8 @@ impl ControllerState { key_or_gamepad (Scancode::Right, Button::DPadRight), key_or_gamepad (Scancode::Up, Button::DPadUp), key_or_gamepad (Scancode::Down, Button::DPadDown), + b (Button::LeftShoulder), + b (Button::RightShoulder), ], analog_left_x: axis_or_zero (Axis::LeftX), analog_left_y: axis_or_zero (Axis::LeftY), @@ -176,6 +178,12 @@ impl ControllerState { if self.is_pressed (KEY_DOWN) { delta = delta.mul_quat (Quat::from_rotation_x (spin_f)); } + if self.is_pressed (YAW_LEFT) { + delta = delta.mul_quat (Quat::from_rotation_z (spin_f)); + } + if self.is_pressed (YAW_RIGHT) { + delta = delta.mul_quat (Quat::from_rotation_z (-spin_f)); + } //println! ("spin_f {}, Quat {:?}", spin_f, delta); @@ -225,6 +233,8 @@ struct Airplane { } struct FlightState { + frames: u64, + airplane: Airplane, spin_speed: i32, arrows: Vec , @@ -234,6 +244,8 @@ struct FlightState { impl Default for FlightState { fn default () -> Self { Self { + frames: 0, + airplane: Airplane { pos: (0.0, -20.0, 20.0).into (), vel: (0.0, 0.0, 0.0).into (), @@ -337,6 +349,8 @@ impl FlightState { ); } } + + self.frames += 1; } } @@ -470,6 +484,7 @@ struct GameGraphics { mesh_sky: RenderableModel, mesh_pitch: RenderableModel, mesh_arrow: RenderableModel, + mesh_truck: RenderableModel, texture_sky: Texture, texture_grass: Texture, @@ -535,6 +550,7 @@ impl GameGraphics { let mesh_sky = renderable_from_iqm_file ("sky-sphere.iqm"); let mesh_pitch = renderable_from_iqm_file ("pitch.iqm"); let mesh_arrow = renderable_from_iqm_file ("arrow.iqm"); + let mesh_truck = renderable_from_iqm_file ("truk.iqm"); let texture_sky = Texture::from_file ("sky.png"); let texture_grass = Texture::from_file ("grass.png"); @@ -795,6 +811,7 @@ impl GameGraphics { mesh_sky, mesh_pitch, mesh_arrow, + mesh_truck, texture_sky, texture_grass, @@ -853,7 +870,7 @@ impl GameGraphics { let proj_mat = Mat4::perspective_rh_gl (30.0f32.to_radians (), screen_size.0 / screen_size.1, 0.125, 200.0); - let airplane_scale = 1.0 / 128.0; + let airplane_scale = 1.0 / 8.0; let view_mat = match state.play_mode { PlayMode::WindTunnel => { @@ -863,14 +880,16 @@ impl GameGraphics { let latitude = (state.camera.altitude - 90.0).to_radians (); proj_mat * - Mat4::from_translation (Vec3::from ((0.0, 0.0, -8.0))) * + Mat4::from_translation (Vec3::from ((0.0, 0.0, -20.0))) * Mat4::from_rotation_x (latitude) * Mat4::from_rotation_z (longitude) * Mat4::from_translation ((0.0, 0.0, -2.7 * 0.5).into ()) }, PlayMode::FreeFlight => { + + proj_mat * - Mat4::from_translation (Vec3::from ((0.0, -4.8, -32.0)) * airplane_scale) * + Mat4::from_translation (Vec3::from ((0.0, -1.2, -8.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 ()) * @@ -881,6 +900,13 @@ impl GameGraphics { let airplane_model_mat = airplane_model_mat * Mat4::from_scale ((airplane_scale, airplane_scale, airplane_scale).into ()); + let truck_model_mat = + Mat4::from_rotation_z ((state.flight.frames as f32).to_radians ()) * + Mat4::from_translation (Vec3::from ((1.0, 0.0, 0.0))) + ; + let inverse_truck = truck_model_mat.inverse (); + let truck_model_mat = truck_model_mat * Mat4::from_scale ((airplane_scale, airplane_scale, airplane_scale).into ()); + let world_model_mat = Mat4::identity (); use uniforms::*; @@ -891,23 +917,41 @@ impl GameGraphics { let unis = shader_vars.unis; let attrs = shader_vars.attrs; - let mvp = view_mat * airplane_model_mat; - glezz::uniform_matrix_4fv (unis [&MVP], &mvp); - - let object_space_light = make_object_space_vec (&inverse_airplane, &light); - let object_space_sky = make_object_space_vec (&inverse_airplane, &Vec3::from ((0.0, 0.0, 1.0))); - - glezz::uniform_3fv (unis [&MIN_BRIGHT], &black); - glezz::uniform_3fv (unis [&MIN_ALBEDO], &white); - glezz::uniform_3fv (unis [&OBJECT_SPACE_LIGHT], &object_space_light); - glezz::uniform_3fv (unis [&OBJECT_SPACE_SKY], &object_space_sky); - let gunmetal_grey = color_from_255 ((133.0, 149.0, 161.0)); glezz::uniform_3fv (unis [&ALBEDO], &gunmetal_grey); - self.mesh_airplane.draw_all (attrs, |_i| { - true - }); + glezz::uniform_3fv (unis [&MIN_BRIGHT], &black); + glezz::uniform_3fv (unis [&MIN_ALBEDO], &white); + + { + let mvp = view_mat * airplane_model_mat; + glezz::uniform_matrix_4fv (unis [&MVP], &mvp); + + let object_space_light = make_object_space_vec (&inverse_airplane, &light); + let object_space_sky = make_object_space_vec (&inverse_airplane, &Vec3::from ((0.0, 0.0, 1.0))); + + glezz::uniform_3fv (unis [&OBJECT_SPACE_LIGHT], &object_space_light); + glezz::uniform_3fv (unis [&OBJECT_SPACE_SKY], &object_space_sky); + + self.mesh_airplane.draw_all (attrs, |_i| { + true + }); + } + + { + let mvp = view_mat * truck_model_mat; + glezz::uniform_matrix_4fv (unis [&MVP], &mvp); + + let object_space_light = make_object_space_vec (&inverse_truck, &light); + let object_space_sky = make_object_space_vec (&inverse_truck, &Vec3::from ((0.0, 0.0, 1.0))); + + glezz::uniform_3fv (unis [&OBJECT_SPACE_LIGHT], &object_space_light); + glezz::uniform_3fv (unis [&OBJECT_SPACE_SKY], &object_space_sky); + + self.mesh_truck.draw_all (attrs, |_| { + true + }); + } let mvp = view_mat * world_model_mat; glezz::uniform_matrix_4fv (unis [&MVP], &mvp); @@ -947,6 +991,11 @@ impl GameGraphics { self.mesh_airplane.draw_all (attrs, |_| true); + let mvp = view_mat * truck_model_mat; + glezz::uniform_matrix_4fv (unis [&MVP], &mvp); + + self.mesh_truck.draw_all (attrs, |_| true); + let mvp = view_mat * world_model_mat; glezz::uniform_matrix_4fv (unis [&MVP], &mvp); diff --git a/truk.iqm b/truk.iqm new file mode 100644 index 0000000..b5474a7 Binary files /dev/null and b/truk.iqm differ