improved file structure and started to add particles
This commit is contained in:
@ -1,16 +1,43 @@
|
||||
use memoffset::offset_of;
|
||||
use ash::vk;
|
||||
use rand::{thread_rng, distributions::{Distribution, Uniform}};
|
||||
use cgmath::{InnerSpace, Vector2, Vector4};
|
||||
use num::traits::FloatConst;
|
||||
use crate::utility::constants::*;
|
||||
use std::f32::consts::PI;
|
||||
|
||||
const PARTICLE_COUNT: i32 = 1000;
|
||||
|
||||
#[repr(C)]
|
||||
#[derive(Clone, Debug, Copy)]
|
||||
pub struct Particle {
|
||||
pos: [f32; 2],
|
||||
vel: [f32; 4],
|
||||
color: [f32; 4],
|
||||
pos: Vector2<f32>,
|
||||
vel: Vector2<f32>,
|
||||
color: Vector4<f32>,
|
||||
}
|
||||
|
||||
impl Particle {
|
||||
pub fn gen() -> Vec<Self> {
|
||||
let mut res = vec![];
|
||||
|
||||
let between = Uniform::from(0.0..1.0);
|
||||
let mut rng = thread_rng();
|
||||
|
||||
for i in 0..PARTICLE_COUNT {
|
||||
let r = (between.sample(&mut rng) as f32).sqrt();
|
||||
let theta = between.sample(&mut rng) * 2.0 * PI;
|
||||
let x = r * theta.cos() * WINDOW_HEIGHT as f32 * WINDOW_WIDTH as f32;
|
||||
let y = r * theta.sin();
|
||||
res.push(
|
||||
Particle {
|
||||
pos: Vector2::new(x, y),
|
||||
vel: Vector2::new(x, y).normalize() * 0.00025,
|
||||
color: Vector4::new(between.sample(&mut rng), between.sample(&mut rng), between.sample(&mut rng), 1.0),
|
||||
}
|
||||
)
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
|
@ -1,5 +1,5 @@
|
||||
use crate::{
|
||||
shaders::*, entities::*, utility, utility::constants::*, utility::debug::*, utility::share, utility::structures::*,
|
||||
shaders::*, entities::*, utility, utility::constants::*, utility::debug::*, utility::share, utility::share::*, utility::structures::*,
|
||||
};
|
||||
|
||||
use ash::{vk, Entry};
|
||||
@ -96,24 +96,24 @@ impl VulkanApp {
|
||||
&surface_stuff,
|
||||
&queue_family,
|
||||
);
|
||||
let swapchain_imageviews = share::v1::create_image_views(
|
||||
let swapchain_imageviews = share::create_image_views(
|
||||
&device,
|
||||
swapchain_stuff.swapchain_format,
|
||||
&swapchain_stuff.swapchain_images,
|
||||
);
|
||||
let render_pass = share::v1::create_render_pass(&device, swapchain_stuff.swapchain_format);
|
||||
let render_pass = share::create_render_pass(&device, swapchain_stuff.swapchain_format);
|
||||
let (graphics_pipeline, pipeline_layout) = VulkanApp::create_graphics_pipeline(
|
||||
&device,
|
||||
render_pass,
|
||||
swapchain_stuff.swapchain_extent,
|
||||
);
|
||||
let swapchain_framebuffers = share::v1::create_framebuffers(
|
||||
let swapchain_framebuffers = share::create_framebuffers(
|
||||
&device,
|
||||
render_pass,
|
||||
&swapchain_imageviews,
|
||||
swapchain_stuff.swapchain_extent,
|
||||
);
|
||||
let command_pool = share::v1::create_command_pool(&device, &queue_family);
|
||||
let command_pool = share::create_command_pool(&device, &queue_family);
|
||||
let (vertex_buffer, vertex_buffer_memory) =
|
||||
VulkanApp::create_vertex_buffer(&instance, &device, physical_device);
|
||||
let command_buffers = VulkanApp::create_command_buffers(
|
||||
@ -125,7 +125,7 @@ impl VulkanApp {
|
||||
swapchain_stuff.swapchain_extent,
|
||||
vertex_buffer,
|
||||
);
|
||||
let sync_ojbects = share::v1::create_sync_objects(&device, MAX_FRAMES_IN_FLIGHT);
|
||||
let sync_ojbects = share::create_sync_objects(&device, MAX_FRAMES_IN_FLIGHT);
|
||||
|
||||
// cleanup(); the 'drop' function will take care of it.
|
||||
VulkanApp {
|
||||
@ -674,12 +674,12 @@ impl VulkanApp {
|
||||
self.swapchain_format = swapchain_stuff.swapchain_format;
|
||||
self.swapchain_extent = swapchain_stuff.swapchain_extent;
|
||||
|
||||
self.swapchain_imageviews = share::v1::create_image_views(
|
||||
self.swapchain_imageviews = share::create_image_views(
|
||||
&self.device,
|
||||
self.swapchain_format,
|
||||
&self.swapchain_images,
|
||||
);
|
||||
self.render_pass = share::v1::create_render_pass(&self.device, self.swapchain_format);
|
||||
self.render_pass = share::create_render_pass(&self.device, self.swapchain_format);
|
||||
let (graphics_pipeline, pipeline_layout) = VulkanApp::create_graphics_pipeline(
|
||||
&self.device,
|
||||
self.render_pass,
|
||||
@ -688,7 +688,7 @@ impl VulkanApp {
|
||||
self.graphics_pipeline = graphics_pipeline;
|
||||
self.pipeline_layout = pipeline_layout;
|
||||
|
||||
self.swapchain_framebuffers = share::v1::create_framebuffers(
|
||||
self.swapchain_framebuffers = share::create_framebuffers(
|
||||
&self.device,
|
||||
self.render_pass,
|
||||
&self.swapchain_imageviews,
|
||||
|
2017
src/utility/share.rs
2017
src/utility/share.rs
File diff suppressed because it is too large
Load Diff
@ -133,23 +133,3 @@ impl VertexV3 {
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
pub const RECT_VERTICES_DATA: [VertexV1; 4] = [
|
||||
VertexV1 {
|
||||
pos: [-0.5, -0.5],
|
||||
color: [1.0, 0.0, 0.0],
|
||||
},
|
||||
VertexV1 {
|
||||
pos: [0.5, -0.5],
|
||||
color: [0.0, 1.0, 0.0],
|
||||
},
|
||||
VertexV1 {
|
||||
pos: [0.5, 0.5],
|
||||
color: [0.0, 0.0, 1.0],
|
||||
},
|
||||
VertexV1 {
|
||||
pos: [-0.5, 0.5],
|
||||
color: [1.0, 1.0, 1.0],
|
||||
},
|
||||
];
|
||||
pub const RECT_INDICES_DATA: [u32; 6] = [0, 1, 2, 2, 3, 0];
|
||||
|
Reference in New Issue
Block a user