three_d/renderer/object/
axes.rs1use crate::renderer::*;
2
3pub struct Axes {
8 model: Gm<InstancedMesh, ColorMaterial>,
9}
10
11impl Axes {
12 pub fn new(context: &Context, radius: f32, length: f32) -> Self {
16 let mut cpu_mesh = CpuMesh::arrow(0.9, 0.6, 16);
17 cpu_mesh
18 .transform(Mat4::from_nonuniform_scale(length, radius, radius))
19 .unwrap();
20 let model = Gm::new(
21 InstancedMesh::new(
22 context,
23 &Instances {
24 transformations: vec![
25 Mat4::identity(),
26 Mat4::from_angle_z(degrees(90.0)),
27 Mat4::from_angle_y(degrees(-90.0)),
28 ],
29 texture_transformations: None,
30 colors: Some(vec![Srgba::RED, Srgba::GREEN, Srgba::BLUE]),
31 },
32 &cpu_mesh,
33 ),
34 ColorMaterial::default(),
35 );
36 Self { model }
37 }
38}
39
40impl<'a> IntoIterator for &'a Axes {
41 type Item = &'a dyn Object;
42 type IntoIter = std::iter::Once<&'a dyn Object>;
43
44 fn into_iter(self) -> Self::IntoIter {
45 std::iter::once(self)
46 }
47}
48
49use std::ops::Deref;
50impl Deref for Axes {
51 type Target = Gm<InstancedMesh, ColorMaterial>;
52 fn deref(&self) -> &Self::Target {
53 &self.model
54 }
55}
56
57impl std::ops::DerefMut for Axes {
58 fn deref_mut(&mut self) -> &mut Self::Target {
59 &mut self.model
60 }
61}
62
63impl Geometry for Axes {
64 impl_geometry_body!(deref);
65
66 fn animate(&mut self, time: f32) {
67 self.model.animate(time)
68 }
69}
70
71impl Object for Axes {
72 impl_object_body!(deref);
73}