use super::*;
#[derive(Clone, Debug)]
pub struct AxesInstance {
pub local: Transform3f,
pub depth_test: Option<Compare>,
}
#[derive(Debug)]
pub struct AxesModel {
pub shader: ShaderProgram,
pub vertices: VertexBuffer,
pub vertices_len: u32,
pub indices: IndexBuffer,
pub indices_len: u32,
}
impl AxesModel {
pub fn create(g: &mut Graphics, shader: ShaderProgram) -> AxesModel {
let vertices = g.vertex_buffer(&VERTICES, BufferUsage::Static);
let vertices_len = VERTICES.len() as u32;
let indices = g.index_buffer(&INDICES, vertices_len as u8, BufferUsage::Static);
let indices_len = INDICES.len() as u32;
AxesModel { shader, vertices, vertices_len, indices, indices_len }
}
pub fn draw(&self, g: &mut Graphics, camera: &camera::Camera, instance: &AxesInstance) {
let uniforms = ColorUniform3 {
transform: camera.view_proj * instance.local,
colormod: Vec4f::ONE,
};
g.draw_indexed(&DrawIndexedArgs {
scissor: None,
blend_mode: BlendMode::Solid,
depth_test: instance.depth_test,
cull_mode: None,
mask: DrawMask::ALL,
prim_type: PrimType::Lines,
shader: self.shader,
uniforms: &[&uniforms],
vertices: &[DrawVertexBuffer {
buffer: self.vertices,
divisor: VertexDivisor::PerVertex,
}],
indices: self.indices,
index_start: 0,
index_end: self.indices_len,
instances: -1,
});
}
}
const RED: [u8; 4] = [245, 59, 39, 255];
const GREEN: [u8; 4] = [181, 255, 104, 255];
const BLUE: [u8; 4] = [7, 111, 255, 255];
static VERTICES: [ColorVertex3; 27] = [
ColorVertex3 { pos: Vec3f::new(0.0, 0.0, 0.0), color: RED },
ColorVertex3 { pos: Vec3f::new(1.0, 0.0, 0.0), color: RED },
ColorVertex3 { pos: Vec3f::new(0.9, 0.05, 0.0), color: RED },
ColorVertex3 { pos: Vec3f::new(1.0, 0.0, 0.0), color: RED },
ColorVertex3 { pos: Vec3f::new(0.9, -0.05, 0.0), color: RED },
ColorVertex3 { pos: Vec3f::new(1.1, 0.04, 0.04), color: RED },
ColorVertex3 { pos: Vec3f::new(1.1, -0.04, -0.04), color: RED },
ColorVertex3 { pos: Vec3f::new(1.1, 0.04, -0.04), color: RED },
ColorVertex3 { pos: Vec3f::new(1.1, -0.04, 0.04), color: RED },
ColorVertex3 { pos: Vec3f::new(0.0, 0.0, 0.0), color: GREEN },
ColorVertex3 { pos: Vec3f::new(0.0, 1.0, 0.0), color: GREEN },
ColorVertex3 { pos: Vec3f::new(0.05, 0.9, 0.0), color: GREEN },
ColorVertex3 { pos: Vec3f::new(0.0, 1.0, 0.0), color: GREEN },
ColorVertex3 { pos: Vec3f::new(-0.05, 0.9, 0.0), color: GREEN },
ColorVertex3 { pos: Vec3f::new(0.03, 1.1, 0.04), color: GREEN },
ColorVertex3 { pos: Vec3f::new(0.0, 1.1, 0.0), color: GREEN },
ColorVertex3 { pos: Vec3f::new(-0.03, 1.1, 0.04), color: GREEN },
ColorVertex3 { pos: Vec3f::new(0.0, 1.1, -0.04), color: GREEN },
ColorVertex3 { pos: Vec3f::new(0.0, 0.0, 0.0), color: BLUE },
ColorVertex3 { pos: Vec3f::new(0.0, 0.0, 1.0), color: BLUE },
ColorVertex3 { pos: Vec3f::new(0.05, 0.0, 0.9), color: BLUE },
ColorVertex3 { pos: Vec3f::new(0.0, 0.0, 1.0), color: BLUE },
ColorVertex3 { pos: Vec3f::new(-0.05, 0.0, 0.9), color: BLUE },
ColorVertex3 { pos: Vec3f::new(-0.04, 0.04, 1.1), color: BLUE },
ColorVertex3 { pos: Vec3f::new(0.04, 0.04, 1.1), color: BLUE },
ColorVertex3 { pos: Vec3f::new(-0.04, -0.04, 1.1), color: BLUE },
ColorVertex3 { pos: Vec3f::new(0.04, -0.04, 1.1), color: BLUE },
];
static INDICES: [u8; 34] = [
0, 1, 2, 3, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12, 12, 13, 14, 15, 16, 15, 15, 17,
18, 19, 20, 21, 21, 22, 23, 24, 24, 25, 25, 26, ];