use amethyst_core::{
nalgebra::{Point3, Vector3},
specs::{Component, DenseVecStorage},
};
use crate::{color::Rgba, vertex::PosColorNorm};
pub type DebugLine = PosColorNorm;
#[derive(Debug, Default)]
pub struct DebugLinesComponent {
pub lines: Vec<DebugLine>,
}
impl Component for DebugLinesComponent {
type Storage = DenseVecStorage<Self>;
}
impl DebugLinesComponent {
pub fn new() -> DebugLinesComponent {
DebugLinesComponent {
lines: Vec::<DebugLine>::new(),
}
}
pub fn with_capacity(mut self, capacity: usize) -> Self {
self.lines = Vec::<DebugLine>::with_capacity(capacity);
self
}
pub fn add_direction(&mut self, position: Point3<f32>, direction: Vector3<f32>, color: Rgba) {
let vertex = DebugLine {
position: position.to_homogeneous().xyz().into(),
color: color.into(),
normal: direction.into(),
};
self.lines.push(vertex);
}
pub fn add_line(&mut self, start: Point3<f32>, end: Point3<f32>, color: Rgba) {
let vertex = DebugLine {
position: start.to_homogeneous().xyz().into(),
color: color.into(),
normal: (end - start).into(),
};
self.lines.push(vertex);
}
pub fn clear(&mut self) {
self.lines.clear();
}
}
#[derive(Debug, Default)]
pub struct DebugLines {
pub lines: Vec<DebugLine>,
}
impl DebugLines {
pub fn new() -> DebugLines {
DebugLines {
lines: Vec::<DebugLine>::new(),
}
}
pub fn with_capacity(mut self, capacity: usize) -> Self {
self.lines = Vec::<DebugLine>::with_capacity(capacity);
self
}
pub fn draw_direction(&mut self, position: Point3<f32>, direction: Vector3<f32>, color: Rgba) {
let vertex = DebugLine {
position: position.to_homogeneous().xyz().into(),
color: color.into(),
normal: direction.into(),
};
self.lines.push(vertex);
}
pub fn draw_line(&mut self, start: Point3<f32>, end: Point3<f32>, color: Rgba) {
let vertex = DebugLine {
position: start.to_homogeneous().xyz().into(),
color: color.into(),
normal: (end - start).into(),
};
self.lines.push(vertex);
}
}