use nalgebra::Vector4;
use nalgebra::core::coordinates::XYZW;
use ::render::Barycentric;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum FaceWinding {
Clockwise,
CounterClockwise
}
#[derive(Debug, Clone)]
pub struct ClipVertex<K> where K: Send + Sync + Barycentric {
pub position: Vector4<f32>,
pub uniforms: K,
}
#[derive(Debug, Clone)]
pub struct ScreenVertex<K> where K: Send + Sync + Barycentric {
pub position: Vector4<f32>,
pub uniforms: K,
}
impl<K> ClipVertex<K> where K: Send + Sync + Barycentric {
#[inline(always)]
pub fn new(position: Vector4<f32>, uniforms: K) -> ClipVertex<K> {
ClipVertex { position: position, uniforms: uniforms }
}
pub fn normalize(self, viewport: (f32, f32)) -> ScreenVertex<K> {
ScreenVertex {
position: {
let (width, height) = viewport;
let XYZW { x, y, z, w } = *self.position;
Vector4::new(
(x / w + 1.0) * (width / 2.0),
(1.0 - y / w) * (height / 2.0),
z / w,
1.0 / w
)
},
uniforms: self.uniforms,
}
}
}