use crate::core::{algebra::Vector3, color::Color, visitor::prelude::*};
use std::cell::Cell;
#[derive(Clone, Debug, Visit)]
pub struct Particle {
#[visit(rename = "Pos")]
pub position: Vector3<f32>,
#[visit(rename = "Vel")]
pub velocity: Vector3<f32>,
pub size: f32,
pub size_modifier: f32,
pub initial_lifetime: f32,
pub rotation_speed: f32,
pub rotation: f32,
pub color: Color,
pub(super) alive: bool,
pub(super) emitter_index: u32,
#[visit(rename = "LifeTime")]
pub(super) lifetime: f32,
#[visit(skip)]
pub(super) sqr_distance_to_camera: Cell<f32>,
}
impl Default for Particle {
fn default() -> Self {
Self {
position: Default::default(),
velocity: Default::default(),
size: 1.0,
alive: true,
size_modifier: 0.0,
lifetime: 0.0,
initial_lifetime: 2.0,
rotation_speed: 0.0,
rotation: 0.0,
emitter_index: 0,
color: Color::WHITE,
sqr_distance_to_camera: Cell::new(0.0),
}
}
}
impl Particle {
pub fn with_position(mut self, position: Vector3<f32>) -> Self {
self.position = position;
self
}
pub fn with_velocity(mut self, velocity: Vector3<f32>) -> Self {
self.velocity = velocity;
self
}
pub fn with_size(mut self, size: f32) -> Self {
self.size = size;
self
}
pub fn with_size_modifier(mut self, size_modifier: f32) -> Self {
self.size_modifier = size_modifier;
self
}
pub fn with_initial_lifetime(mut self, initial_lifetime: f32) -> Self {
self.initial_lifetime = initial_lifetime;
self
}
pub fn with_rotation(mut self, rotation: f32) -> Self {
self.rotation = rotation;
self
}
pub fn with_rotation_speed(mut self, rotation_speed: f32) -> Self {
self.rotation_speed = rotation_speed;
self
}
pub fn with_color(mut self, color: Color) -> Self {
self.color = color;
self
}
}