input
This commit is contained in:
29
src/main.rs
29
src/main.rs
@@ -2,12 +2,17 @@ use crate::vulkan::{GameData, Game, LinePoint};
|
||||
use winit::{Event, WindowEvent, ElementState};
|
||||
use std::iter::FromIterator;
|
||||
use cgmath::{Matrix4, Rad, Point3, Vector3, Deg};
|
||||
use crate::input::{InputState, VirtualButton, DigitalInput, VirtualAxis, AxisInput};
|
||||
|
||||
mod vulkan;
|
||||
mod input;
|
||||
|
||||
const PRINT_KEYBOARD_INPUT: bool = false;
|
||||
|
||||
struct TestGame {}
|
||||
struct TestGame {
|
||||
input: InputState,
|
||||
cam_pos: Point3<f32>
|
||||
}
|
||||
|
||||
impl Game for TestGame {
|
||||
fn update(self: &mut Self, game_data: &mut GameData) {
|
||||
@@ -16,7 +21,7 @@ impl Game for TestGame {
|
||||
let model = Matrix4::from_angle_z(Rad::from(Deg(game_data.push_constants.time * 100.0)));
|
||||
|
||||
let view = Matrix4::look_at(
|
||||
Point3::new(2.0, 2.0, 2.0),
|
||||
self.cam_pos,
|
||||
Point3::new(0.0, 0.0, 0.0),
|
||||
Vector3::new(0.0, 0.0, 1.0)
|
||||
);
|
||||
@@ -53,22 +58,34 @@ impl Game for TestGame {
|
||||
}
|
||||
}
|
||||
|
||||
self.input.on_keyboard_event(input.state, input.scancode, input.modifiers);
|
||||
|
||||
if input.state == ElementState::Released && input.modifiers.ctrl && input.scancode == 19 {
|
||||
game_data.recreate_pipeline = true;
|
||||
}
|
||||
if input.state == ElementState::Released && input.scancode == 1 {
|
||||
if self.input.button_down("QUIT") {
|
||||
game_data.shutdown = true;
|
||||
}
|
||||
}
|
||||
},
|
||||
// Event::WindowEvent { event: WindowEvent::MouseInput { device_id, state, button, modifiers }, .. } => {
|
||||
//
|
||||
// }
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut game = TestGame {};
|
||||
let mut game = TestGame {
|
||||
input: InputState::new(),
|
||||
cam_pos: Point3::new(2.0, 2.0, 2.0)
|
||||
};
|
||||
|
||||
game.input.virtual_buttons.insert("QUIT".to_string(), VirtualButton { digital_inputs: vec![DigitalInput::simple_key(1)] });
|
||||
game.input.virtual_axes.insert("FORWARD_CAM_AXIS".to_string(), VirtualAxis { analog_inputs: vec![AxisInput::Digital(DigitalInput::simple_key(87), DigitalInput::simple_key(83))] });
|
||||
|
||||
vulkan::init(
|
||||
"models/box.obj",
|
||||
"models/iski51.obj",
|
||||
(-10..10)
|
||||
.flat_map(|it| vec![
|
||||
LinePoint { position: [it as f32, -10., 0.] },
|
||||
|
||||
Reference in New Issue
Block a user