This commit is contained in:
2019-07-30 12:36:19 +02:00
parent e01ff8d395
commit 5a67eb1042
3 changed files with 380 additions and 336 deletions

View File

@@ -2,7 +2,7 @@ use winit::{Event};
use cgmath::{Matrix4, Rad, Vector3, Deg, Quaternion, Rotation3, One, Rotation, SquareMatrix};
mod vulkan;
use crate::vulkan::{GameData, Game, LinePoint, GameObject};
use crate::vulkan::{GameData, Game, LinePoint, GameObject, VulkanRenderer};
mod input;
use crate::input::{InputState};
@@ -10,16 +10,18 @@ use crate::input::{InputState};
mod config;
use crate::config::LogConfig;
mod mesh;
struct TestGame<'a> {
input: InputState<'a>,
cam_position: Vector3<f32>,
cam_rotation: Quaternion<f32>,
log_config: &'a LogConfig,
}
impl Game for TestGame<'_> {
fn validation_layers_enabled(self: &Self) -> bool {
self.log_config.vulkan_validation_layers
fn game_start(self: &mut Self, _game_data: &mut GameData) {
println!("Game started.");
// let player_mesh = init_data.upload_mesh(mesh::load_mesh("models/iski51.dae").into_iter().nth(0).unwrap());
}
fn update(self: &mut Self, game_data: &mut GameData) {
@@ -53,8 +55,6 @@ impl Game for TestGame<'_> {
self.input.get_axis("move_forward") * 0.05));
// Move game objects
let model = Matrix4::from_angle_z(Rad::from(Deg(game_data.push_constants.time * 100.0)));
let view = Matrix4::from(self.cam_rotation) * Matrix4::from_translation(self.cam_position);
let mut proj = cgmath::perspective(
@@ -66,7 +66,6 @@ impl Game for TestGame<'_> {
proj.y.y *= -1.0;
game_data.push_constants.model = model.into();
game_data.push_constants.view = view.into();
game_data.push_constants.projection = proj.into();
game_data.line_push_constants.view = view.into();
@@ -87,12 +86,10 @@ fn main() {
input: InputState::new("config/input.toml", &log_config),
cam_rotation: Quaternion::one(),
cam_position: Vector3::new(0.0, 0.0, -10.0),
log_config: &log_config,
};
let line_count = 30;
vulkan::init(
vec!["models/cube.dae"],
let mut renderer = VulkanRenderer::init(
(-line_count..=line_count)
.flat_map(|it| vec![
LinePoint { position: [it as f32, -line_count as f32, 0.] },
@@ -100,6 +97,8 @@ fn main() {
LinePoint { position: [-line_count as f32, it as f32, 0.] },
LinePoint { position: [line_count as f32, it as f32, 0.] },
]).collect(),
&mut game
log_config.vulkan_validation_layers,
);
renderer.upload_mesh(mesh::load_mesh("models/cube.dae", true).into_iter().nth(0).unwrap());
renderer.render_loop(&mut game);
}