Skip to main content

pytrace_core/composite/
axes.rs

1use crate::internal::*;
2
3const RED: Texture = Texture::Lambertian(RGB(0.9, 0.1, 0.1));
4const BLUE: Texture = Texture::Lambertian(RGB(0.0, 0.2, 0.7));
5const GREEN: Texture = Texture::Lambertian(RGB(0.0, 0.9, 0.0));
6const BLACK: Texture = Texture::Lambertian(RGB(0.01, 0.01, 0.01));
7
8/// Axes are a debug structure that indicate the position of the origin of the space
9/// as well as the x, y and z directions.
10///
11/// It is also a way to evaluate distances, as it includes spheres with regular spacing.
12/// Its only parameter is in fact its size.
13///
14/// Its major downside is that being composed of almost 20 objects, it slows down rendering
15/// quite a bit.
16#[derive(Clone, Copy)]
17pub struct Axes {
18    pub scale: f64,
19}
20
21#[allow(unused_variables)]
22#[allow(clippy::many_single_char_names)]
23impl Axes {
24    pub fn build(self) -> Composite {
25        let len = self.scale;
26        let rad1 = len * 0.1;
27        let rad2 = len * 0.2;
28        let o = Vec3(0.0, 0.0, 0.0);
29        let x = Vec3(1.0, 0.0, 0.0) * len;
30        let y = Vec3(0.0, 1.0, 0.0) * len;
31        let z = Vec3(0.0, 0.0, 1.0) * len;
32        let orig = Sphere {
33            center: o,
34            radius: rad2,
35            texture: BLACK,
36        };
37        let xdir = EmptyCylinder {
38            center1: o,
39            center2: o + x * 5.0,
40            radius: rad1,
41            texture: RED,
42        };
43        let ydir = EmptyCylinder {
44            center1: o,
45            center2: o + y * 5.0,
46            radius: rad1,
47            texture: BLUE,
48        };
49        let zdir = EmptyCylinder {
50            center1: o,
51            center2: o + z * 5.0,
52            radius: rad1,
53            texture: GREEN,
54        };
55        let mut v = vec![orig];
56        for ix in 1..=5 {
57            v.push(Sphere {
58                center: o + x * ix as f64,
59                radius: rad2,
60                texture: RED,
61            });
62        }
63        for iy in 1..=5 {
64            v.push(Sphere {
65                center: o + y * iy as f64,
66                radius: rad2,
67                texture: BLUE,
68            });
69        }
70        for iz in 1..=5 {
71            v.push(Sphere {
72                center: o + z * iz as f64,
73                radius: rad2,
74                texture: GREEN,
75            });
76        }
77        let mut res = vec![
78            xdir.build().wrap(),
79            ydir.build().wrap(),
80            zdir.build().wrap(),
81        ];
82        for x in v {
83            res.push(x.build().wrap());
84        }
85        res
86    }
87}