🐛 Fix scale factor on the airplane

Add a little truck that drives around.
main
_ 2020-03-15 15:58:45 +00:00
parent 18dffdc871
commit 7e8902a040
3 changed files with 66 additions and 17 deletions

Binary file not shown.

View File

@ -108,6 +108,8 @@ impl ControllerState {
key_or_gamepad (Scancode::Right, Button::DPadRight), key_or_gamepad (Scancode::Right, Button::DPadRight),
key_or_gamepad (Scancode::Up, Button::DPadUp), key_or_gamepad (Scancode::Up, Button::DPadUp),
key_or_gamepad (Scancode::Down, Button::DPadDown), key_or_gamepad (Scancode::Down, Button::DPadDown),
b (Button::LeftShoulder),
b (Button::RightShoulder),
], ],
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),
@ -176,6 +178,12 @@ impl ControllerState {
if self.is_pressed (KEY_DOWN) { if self.is_pressed (KEY_DOWN) {
delta = delta.mul_quat (Quat::from_rotation_x (spin_f)); 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); //println! ("spin_f {}, Quat {:?}", spin_f, delta);
@ -225,6 +233,8 @@ struct Airplane {
} }
struct FlightState { struct FlightState {
frames: u64,
airplane: Airplane, airplane: Airplane,
spin_speed: i32, spin_speed: i32,
arrows: Vec <Arrow>, arrows: Vec <Arrow>,
@ -234,6 +244,8 @@ struct FlightState {
impl Default for FlightState { impl Default for FlightState {
fn default () -> Self { fn default () -> Self {
Self { Self {
frames: 0,
airplane: Airplane { airplane: Airplane {
pos: (0.0, -20.0, 20.0).into (), pos: (0.0, -20.0, 20.0).into (),
vel: (0.0, 0.0, 0.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_sky: RenderableModel,
mesh_pitch: RenderableModel, mesh_pitch: RenderableModel,
mesh_arrow: RenderableModel, mesh_arrow: RenderableModel,
mesh_truck: RenderableModel,
texture_sky: Texture, texture_sky: Texture,
texture_grass: Texture, texture_grass: Texture,
@ -535,6 +550,7 @@ impl GameGraphics {
let mesh_sky = renderable_from_iqm_file ("sky-sphere.iqm"); let mesh_sky = renderable_from_iqm_file ("sky-sphere.iqm");
let mesh_pitch = renderable_from_iqm_file ("pitch.iqm"); let mesh_pitch = renderable_from_iqm_file ("pitch.iqm");
let mesh_arrow = renderable_from_iqm_file ("arrow.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_sky = Texture::from_file ("sky.png");
let texture_grass = Texture::from_file ("grass.png"); let texture_grass = Texture::from_file ("grass.png");
@ -795,6 +811,7 @@ impl GameGraphics {
mesh_sky, mesh_sky,
mesh_pitch, mesh_pitch,
mesh_arrow, mesh_arrow,
mesh_truck,
texture_sky, texture_sky,
texture_grass, 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 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 { let view_mat = match state.play_mode {
PlayMode::WindTunnel => { PlayMode::WindTunnel => {
@ -863,14 +880,16 @@ impl GameGraphics {
let latitude = (state.camera.altitude - 90.0).to_radians (); let latitude = (state.camera.altitude - 90.0).to_radians ();
proj_mat * 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_x (latitude) *
Mat4::from_rotation_z (longitude) * Mat4::from_rotation_z (longitude) *
Mat4::from_translation ((0.0, 0.0, -2.7 * 0.5).into ()) Mat4::from_translation ((0.0, 0.0, -2.7 * 0.5).into ())
}, },
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, -1.2, -8.0)) * airplane_scale) *
Mat4::from_rotation_x (state.flight.lookaround.altitude.to_radians ()) * Mat4::from_rotation_x (state.flight.lookaround.altitude.to_radians ()) *
Mat4::from_rotation_y (state.flight.lookaround.azimuth.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 ()) *
@ -881,6 +900,13 @@ impl GameGraphics {
let airplane_model_mat = airplane_model_mat * let airplane_model_mat = airplane_model_mat *
Mat4::from_scale ((airplane_scale, airplane_scale, airplane_scale).into ()); 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 (); let world_model_mat = Mat4::identity ();
use uniforms::*; use uniforms::*;
@ -891,23 +917,41 @@ impl GameGraphics {
let unis = shader_vars.unis; let unis = shader_vars.unis;
let attrs = shader_vars.attrs; let attrs = shader_vars.attrs;
let gunmetal_grey = color_from_255 ((133.0, 149.0, 161.0));
glezz::uniform_3fv (unis [&ALBEDO], &gunmetal_grey);
glezz::uniform_3fv (unis [&MIN_BRIGHT], &black);
glezz::uniform_3fv (unis [&MIN_ALBEDO], &white);
{
let mvp = view_mat * airplane_model_mat; let mvp = view_mat * airplane_model_mat;
glezz::uniform_matrix_4fv (unis [&MVP], &mvp); glezz::uniform_matrix_4fv (unis [&MVP], &mvp);
let object_space_light = make_object_space_vec (&inverse_airplane, &light); 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))); 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_LIGHT], &object_space_light);
glezz::uniform_3fv (unis [&OBJECT_SPACE_SKY], &object_space_sky); 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| { self.mesh_airplane.draw_all (attrs, |_i| {
true 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; let mvp = view_mat * world_model_mat;
glezz::uniform_matrix_4fv (unis [&MVP], &mvp); glezz::uniform_matrix_4fv (unis [&MVP], &mvp);
@ -947,6 +991,11 @@ impl GameGraphics {
self.mesh_airplane.draw_all (attrs, |_| true); 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; let mvp = view_mat * world_model_mat;
glezz::uniform_matrix_4fv (unis [&MVP], &mvp); glezz::uniform_matrix_4fv (unis [&MVP], &mvp);

BIN
truk.iqm Normal file

Binary file not shown.