You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.4 KiB

use memoffset::offset_of;
use ash::vk;
use rand::{thread_rng, distributions::{Distribution, Uniform}};
use cgmath::{InnerSpace, Vector2, Vector4};
use crate::utility::constants::*;
use std::f32::consts::PI;
const PARTICLE_COUNT: i32 = 1000;
#[repr(C)]
#[derive(Clone, Debug, Copy)]
pub struct Particle {
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)]
#[derive(Clone, Debug, Copy)]
pub struct Vertex {
pos: [f32; 2],
color: [f32; 3],
}
impl Vertex {
pub fn get_binding_description() -> [vk::VertexInputBindingDescription; 1] {
[vk::VertexInputBindingDescription {
binding: 0,
stride: std::mem::size_of::<Vertex>() as u32,
input_rate: vk::VertexInputRate::VERTEX,
}]
}
pub fn get_attribute_descriptions() -> [vk::VertexInputAttributeDescription; 2] {
[
vk::VertexInputAttributeDescription {
binding: 0,
location: 0,
format: vk::Format::R32G32_SFLOAT,
offset: offset_of!(Vertex, pos) as u32,
},
vk::VertexInputAttributeDescription {
binding: 0,
location: 1,
format: vk::Format::R32G32B32_SFLOAT,
offset: offset_of!(Vertex, color) as u32,
},
]
}
}
pub const TRI_VERT_DATA: [Vertex; 3] = [
Vertex {
pos: [0.0, -0.5],
color: [1.0, 1.0, 1.0],
},
Vertex {
pos: [0.5, 0.5],
color: [0.0, 1.0, 0.0],
},
Vertex {
pos: [-0.5, 0.5],
color: [0.0, 0.0, 1.0],
},
];