use fastrand::f32;
use crate::{
Evolution, Tf, Cl, Transformation, Colorization,
D_TRANSFORMATION_SPEED_EVOLUTION, D_TRANSFORMATION_START_TIME, D_TRANSFORMATION_END_TIME,
D_COLORIZATION_SPEED_EVOLUTION, D_COLORIZATION_START_TIME, D_COLORIZATION_END_TIME,
};
pub struct Vertex {
pub position: [f32; 3],
pub color: [f32; 4],
pub t: Vec<Tf>,
pub c: Vec<Cl>,
}
impl Vertex {
pub fn new() -> Self {
unsafe {
Self {
position: super::D_VERTEX_POSITION,
color: if super::D_RANDOM_VERTEX_COLOR {
[f32(), f32(), f32(), super::D_VERTEX_ALPHA]
} else {
[
super::D_VERTEX_COLOR[0],
super::D_VERTEX_COLOR[1],
super::D_VERTEX_COLOR[2],
super::D_VERTEX_ALPHA,
]
},
t: vec![],
c: vec![],
}
}
}
pub fn pos(mut self, x: f32, y: f32, z: f32) -> Self {
self.position = [x, y, z];
self
}
pub fn r(mut self, red: f32) -> Self {
self.color[0] = red;
self
}
pub fn g(mut self, green: f32) -> Self {
self.color[1] = green;
self
}
pub fn b(mut self, blue: f32) -> Self {
self.color[2] = blue;
self
}
pub fn a(mut self, alpha: f32) -> Self {
self.color[3] = alpha;
self
}
pub fn rgb(mut self, red: f32, green: f32, blue: f32) -> Self {
self.color = [red, green, blue, self.color[3]];
self
}
pub fn rgba(mut self, red: f32, green: f32, blue: f32, alpha: f32) -> Self {
self.color = [red, green, blue, alpha];
self
}
pub(crate) fn set_rgb(&mut self, red: f32, green: f32, blue: f32) {
self.color = [red, green, blue, self.color[3]];
}
pub(crate) fn set_alpha(&mut self, alpha: f32) {
self.color[3] = alpha;
}
pub fn transform(mut self, transformation: Transformation) -> Self {
self.t.push(Tf {
t: transformation,
e: unsafe { D_TRANSFORMATION_SPEED_EVOLUTION },
start: unsafe { D_TRANSFORMATION_START_TIME },
end: unsafe { D_TRANSFORMATION_END_TIME },
});
self
}
pub fn recolor(mut self, colorization: Colorization) -> Self {
self.c.push(Cl {
c: colorization,
e: unsafe { D_COLORIZATION_SPEED_EVOLUTION },
start: unsafe { D_COLORIZATION_START_TIME },
end: unsafe { D_COLORIZATION_END_TIME },
});
self
}
pub fn evolution_c(mut self, e: Evolution) -> Self {
self.c.last_mut().unwrap().e = e;
self
}
pub fn start_c(mut self, start: f32) -> Self {
self.c.last_mut().unwrap().start = start;
self
}
pub fn end_c(mut self, end: f32) -> Self {
self.c.last_mut().unwrap().end = end;
self
}
pub fn evolution_t(mut self, e: Evolution) -> Self {
self.t.last_mut().unwrap().e = e;
self
}
pub fn start_t(mut self, start: f32) -> Self {
self.t.last_mut().unwrap().start = start;
self
}
pub fn end_t(mut self, end: f32) -> Self {
self.t.last_mut().unwrap().end = end;
self
}
}