shade 0.0.5

Another graphics library
Documentation
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] = [
	// X axis [0]
	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 },

	// Y axis [9]
	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 },

	// Z axis [18]
	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] = [
	// X axis
	0, 1,       // axis line
	2, 3, 3, 4, // arrowhead lines
	5, 6, 7, 8, // letter X lines

	// Y axis
	9, 10,      // axis line
	11, 12, 12, 13, // arrowhead lines
	14, 15, 16, 15, 15, 17, // letter Y lines

	// Z axis
	18, 19,     // axis line
	20, 21, 21, 22, // arrowhead lines
	23, 24, 24, 25, 25, 26, // letter Z lines
];