This commit is contained in:
2019-07-26 03:33:03 +02:00
parent 767efab3d4
commit 8c14653cfc
5 changed files with 52 additions and 30 deletions

View File

@@ -2,9 +2,10 @@ use crate::vulkan::{Vertex, GameData};
use winit::{Event, WindowEvent, ElementState};
use std::time::SystemTime;
use std::iter::FromIterator;
use cgmath::{Matrix4, SquareMatrix, Rad, Point3, Vector3};
use cgmath::{Matrix4, SquareMatrix, Rad, Point3, Vector3, Deg};
mod vulkan;
use vulkan::vs::ty::PushConstants;
const PRINT_KEYBOARD_INPUT: bool = false;
@@ -40,29 +41,40 @@ impl GameData<'_> {
fn update_push_constants(self: &mut Self) {
self.push_constants.time = self.start_time.elapsed().unwrap().as_millis() as f32 / 1000.0;
self.push_constants.model = Matrix4::identity();
self.push_constants.view = Matrix4::look_at(Point3::new(f32::sin(self.push_constants.time), 0.0, f32::cos(self.push_constants.time)), Point3::new(0.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 0.0));
self.push_constants.projection = cgmath::perspective(Rad(std::f32::consts::FRAC_PI_2), self.aspect_ratio, 0.01, 100.0);
let model = Matrix4::from_angle_z(Rad::from(Deg(self.push_constants.time * 100.0)));
let view = Matrix4::look_at(
Point3::new(2.0, 2.0, 2.0),
Point3::new(0.0, 0.0, 0.0),
Vector3::new(0.0, 0.0, 1.0)
);
let mut proj = cgmath::perspective(
Rad::from(Deg(45.0)),
self.aspect_ratio,
0.1,
10.0
);
proj.y.y *= -1.0;
self.push_constants.model = model.into();
self.push_constants.view = view.into();
self.push_constants.projection = proj.into();
}
}
#[derive(Debug, Clone, Copy)]
pub struct PushConstants {
pub time: f32,
pub model: Matrix4<f32>,
pub view: Matrix4<f32>,
pub projection: Matrix4<f32>,
}
fn main() {
let mut whatever = String::new();
std::io::stdin().read_line(&mut whatever).unwrap();
// let mut whatever = String::new();
// std::io::stdin().read_line(&mut whatever).unwrap();
let mut pc = PushConstants {
time: 0.0,
model: Matrix4::identity(),
view: Matrix4::identity(),
projection: Matrix4::identity()
_dummy0: [0; 12],
model: Matrix4::identity().into(),
view: Matrix4::identity().into(),
projection: Matrix4::identity().into(),
};
let data = GameData {