2019-05-05 14:52:27 +00:00
|
|
|
use log;
|
|
|
|
use env_logger;
|
2020-03-15 15:43:15 +00:00
|
|
|
use std::sync::Arc;
|
2020-03-15 23:24:28 +00:00
|
|
|
use std::time;
|
2020-01-26 00:57:15 +00:00
|
|
|
|
|
|
|
use cgmath as cgm;
|
2019-05-05 14:52:27 +00:00
|
|
|
|
|
|
|
mod render;
|
2020-01-20 01:00:14 +00:00
|
|
|
mod util;
|
2020-07-13 20:58:24 +00:00
|
|
|
mod physics;
|
2019-05-05 14:52:27 +00:00
|
|
|
|
2020-01-26 00:57:15 +00:00
|
|
|
use render::vulkan::data;
|
2020-07-20 19:16:29 +00:00
|
|
|
use render::material::{Texture, PBRMaterialBuilder};
|
|
|
|
use render::mesh::Mesh;
|
|
|
|
use render::renderable::{Object, Renderable, ResourceManager};
|
2020-07-13 20:58:24 +00:00
|
|
|
use physics::color;
|
2020-01-26 00:57:15 +00:00
|
|
|
|
2019-05-05 14:52:27 +00:00
|
|
|
fn main() {
|
|
|
|
env_logger::init();
|
|
|
|
log::info!("Starting...");
|
2020-01-26 00:57:15 +00:00
|
|
|
|
2020-05-29 22:56:20 +00:00
|
|
|
let mut rm = ResourceManager::new();
|
|
|
|
|
2020-07-13 21:33:18 +00:00
|
|
|
let mesh = {
|
2020-03-15 15:43:15 +00:00
|
|
|
let vertices = Arc::new(vec![
|
2020-05-08 22:40:43 +00:00
|
|
|
data::Vertex::new([-0.5, -0.5, 0.5], [1.0, 1.0, 1.0], [1.0, 0.0]),
|
|
|
|
data::Vertex::new([0.5, -0.5, 0.5], [1.0, 1.0, 0.0], [0.0, 0.0]),
|
|
|
|
data::Vertex::new([0.5, 0.5, 0.5], [0.0, 1.0, 1.0], [0.0, 1.0]),
|
|
|
|
data::Vertex::new([-0.5, 0.5, 0.5], [1.0, 0.0, 1.0], [1.0, 1.0]),
|
|
|
|
|
|
|
|
data::Vertex::new([0.5, -0.5, -0.5], [1.0, 1.0, 1.0], [0.0, 1.0]),
|
|
|
|
data::Vertex::new([0.5, 0.5, -0.5], [1.0, 1.0, 0.0], [1.0, 1.0]),
|
|
|
|
data::Vertex::new([0.5, 0.5, 0.5], [0.0, 1.0, 1.0], [1.0, 0.0]),
|
|
|
|
data::Vertex::new([0.5, -0.5, 0.5], [1.0, 0.0, 1.0], [0.0, 0.0]),
|
|
|
|
|
|
|
|
data::Vertex::new([-0.5, -0.5, -0.5], [1.0, 1.0, 1.0], [1.0, 1.0]),
|
|
|
|
data::Vertex::new([-0.5, 0.5, -0.5], [1.0, 1.0, 0.0], [0.0, 1.0]),
|
|
|
|
data::Vertex::new([-0.5, 0.5, 0.5], [0.0, 1.0, 1.0], [0.0, 0.0]),
|
|
|
|
data::Vertex::new([-0.5, -0.5, 0.5], [1.0, 0.0, 1.0], [1.0, 0.0]),
|
|
|
|
|
|
|
|
data::Vertex::new([-0.5, -0.5, -0.5], [1.0, 1.0, 1.0], [0.0, 1.0]),
|
|
|
|
data::Vertex::new([0.5, -0.5, -0.5], [1.0, 1.0, 0.0], [1.0, 1.0]),
|
|
|
|
data::Vertex::new([0.5, -0.5, 0.5], [0.0, 1.0, 1.0], [1.0, 0.0]),
|
|
|
|
data::Vertex::new([-0.5, -0.5, 0.5], [1.0, 0.0, 1.0], [0.0, 0.0]),
|
|
|
|
|
|
|
|
data::Vertex::new([-0.5, 0.5, -0.5], [1.0, 1.0, 1.0], [1.0, 1.0]),
|
|
|
|
data::Vertex::new([0.5, 0.5, -0.5], [1.0, 1.0, 0.0], [0.0, 1.0]),
|
|
|
|
data::Vertex::new([0.5, 0.5, 0.5], [0.0, 1.0, 1.0], [0.0, 0.0]),
|
|
|
|
data::Vertex::new([-0.5, 0.5, 0.5], [1.0, 0.0, 1.0], [1.0, 0.0]),
|
|
|
|
|
|
|
|
data::Vertex::new([-0.5, -0.5, -0.5], [1.0, 1.0, 1.0], [0.0, 0.0]),
|
|
|
|
data::Vertex::new([0.5, -0.5, -0.5], [1.0, 1.0, 0.0], [1.0, 0.0]),
|
|
|
|
data::Vertex::new([0.5, 0.5, -0.5], [0.0, 1.0, 1.0], [1.0, 1.0]),
|
|
|
|
data::Vertex::new([-0.5, 0.5, -0.5], [1.0, 0.0, 1.0], [0.0, 1.0]),
|
2020-03-14 15:55:03 +00:00
|
|
|
]);
|
2020-03-15 15:43:15 +00:00
|
|
|
let indices = Arc::new(vec![
|
2020-05-08 22:40:43 +00:00
|
|
|
0, 1, 2, 2, 3, 0,
|
|
|
|
|
2020-03-15 23:24:28 +00:00
|
|
|
4, 5, 6, 6, 7, 4,
|
2020-05-08 22:40:43 +00:00
|
|
|
8, 10, 9, 10, 8, 11,
|
|
|
|
|
|
|
|
12, 13, 14, 14, 15, 12,
|
|
|
|
16, 18, 17, 18, 16, 19,
|
|
|
|
|
|
|
|
20, 22, 21, 22, 20, 23,
|
2020-03-15 23:24:28 +00:00
|
|
|
|
2020-03-14 15:55:03 +00:00
|
|
|
]);
|
2020-07-13 21:06:39 +00:00
|
|
|
rm.add_mesh(Mesh::new(vertices, indices))
|
2020-03-15 22:48:07 +00:00
|
|
|
};
|
|
|
|
|
2020-07-20 19:16:29 +00:00
|
|
|
let material = rm.add_material(PBRMaterialBuilder {
|
2020-07-13 21:33:18 +00:00
|
|
|
diffuse: Texture::from_image(String::from("assets/test-128px.png")),
|
|
|
|
roughness: Texture::from_color(color::LinearF32::new(1.0)),
|
2020-07-20 19:16:29 +00:00
|
|
|
}.build());
|
2020-05-08 22:40:43 +00:00
|
|
|
|
2020-03-15 23:24:28 +00:00
|
|
|
|
2020-05-29 22:56:20 +00:00
|
|
|
let mut cubes: Vec<Box<Object>> = vec![];
|
2020-03-16 00:30:36 +00:00
|
|
|
for x in -20..20 {
|
|
|
|
for y in -20..20 {
|
|
|
|
for z in -20..20 {
|
2020-03-16 00:03:59 +00:00
|
|
|
let transform = cgm::Matrix4::from_translation(cgm::Vector3::new((x as f32)*4.0, (y as f32)*4.0, (z as f32)*4.0));
|
2020-03-15 23:24:28 +00:00
|
|
|
let cube = render::renderable::Object {
|
2020-07-13 21:33:18 +00:00
|
|
|
mesh, material, transform,
|
2020-03-15 23:24:28 +00:00
|
|
|
};
|
2020-05-29 22:56:20 +00:00
|
|
|
cubes.push(Box::new(cube));
|
2020-03-15 23:24:28 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-14 15:55:03 +00:00
|
|
|
}
|
2020-01-26 00:57:15 +00:00
|
|
|
|
2020-05-29 22:56:20 +00:00
|
|
|
let renderables: Vec<Box<dyn Renderable>> = cubes.into_iter().map(|e| e as Box<dyn Renderable>).collect();
|
2020-03-15 23:24:28 +00:00
|
|
|
|
|
|
|
let start = time::Instant::now();
|
2020-07-13 21:33:18 +00:00
|
|
|
let mut renderer = render::Renderer::initialize();
|
2020-03-15 23:24:28 +00:00
|
|
|
loop {
|
|
|
|
let instant_ns = time::Instant::now().duration_since(start).as_nanos() as u64;
|
|
|
|
let instant = ((instant_ns/1000) as f32) / 1_000_000.0;
|
|
|
|
|
|
|
|
let position = (instant / 10.0) * 3.14 * 2.0;
|
|
|
|
|
|
|
|
let view = cgm::Matrix4::look_at(
|
2020-03-15 23:40:04 +00:00
|
|
|
cgm::Point3::new(
|
|
|
|
position.cos() * 10.0 * (((position*2.0).cos()/2.0)+1.0),
|
|
|
|
position.sin() * 10.0 * (((position*2.0).cos()/2.0)+1.0),
|
2020-03-16 00:03:59 +00:00
|
|
|
3.0
|
2020-03-15 23:40:04 +00:00
|
|
|
),
|
2020-03-15 23:24:28 +00:00
|
|
|
cgm::Point3::new(0.0, 0.0, 0.0),
|
|
|
|
cgm::Vector3::new(0.0, 0.0, 1.0)
|
|
|
|
);
|
|
|
|
|
2020-05-29 22:56:20 +00:00
|
|
|
renderer.draw_frame(&view, &rm, &renderables);
|
2020-03-15 23:24:28 +00:00
|
|
|
if renderer.poll_close() {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2019-05-05 14:52:27 +00:00
|
|
|
}
|