1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
use na;
use na::{Vec3, Pnt2, Pnt3};
use super::{TriMesh, IndexBuffer, Polyline};
use math::{Scalar, Point, Vect};
pub fn cuboid<N>(extents: &Vec3<N>) -> TriMesh<Pnt3<N>>
where N: Scalar {
let mut cuboid = unit_cuboid();
cuboid.scale_by(extents);
cuboid
}
pub fn unit_cuboid<N>() -> TriMesh<Pnt3<N>>
where N: Scalar {
let mut coords = Vec::with_capacity(8);
let mut uvs = Vec::with_capacity(4);
let mut normals = Vec::with_capacity(6);
let mut faces = Vec::with_capacity(12);
let _0_5: N = na::cast(0.5);
let m0_5: N = -_0_5;
let _1: N = na::one();
let m1: N = -_1;
let _0: N = na::zero();
coords.push(Pnt3::new(m0_5.clone(), m0_5.clone(), _0_5.clone()));
coords.push(Pnt3::new(m0_5.clone(), m0_5.clone(), m0_5.clone()));
coords.push(Pnt3::new(_0_5.clone(), m0_5.clone(), m0_5.clone()));
coords.push(Pnt3::new(_0_5.clone(), m0_5.clone(), _0_5.clone()));
coords.push(Pnt3::new(m0_5.clone(), _0_5.clone(), _0_5.clone()));
coords.push(Pnt3::new(m0_5.clone(), _0_5.clone(), m0_5.clone()));
coords.push(Pnt3::new(_0_5.clone(), _0_5.clone(), m0_5.clone()));
coords.push(Pnt3::new(_0_5.clone(), _0_5.clone(), _0_5.clone()));
uvs.push(Pnt2::new(_0.clone(), _1.clone()));
uvs.push(Pnt2::new(_1.clone(), _1.clone()));
uvs.push(Pnt2::new(_0.clone(), _0.clone()));
uvs.push(Pnt2::new(_1.clone(), _0.clone()));
normals.push(Vec3::new(m1.clone(), _0.clone(), _0.clone()));
normals.push(Vec3::new(_0.clone(), _0.clone(), m1.clone()));
normals.push(Vec3::new(_1.clone(), _0.clone(), _0.clone()));
normals.push(Vec3::new(_0.clone(), _0.clone(), _1.clone()));
normals.push(Vec3::new(_0.clone(), m1.clone(), _0.clone()));
normals.push(Vec3::new(_0.clone(), _1.clone(), _0.clone()));
faces.push(Pnt3::new(Pnt3::new(4, 0, 0), Pnt3::new(5, 0, 1), Pnt3::new(0, 0, 2)));
faces.push(Pnt3::new(Pnt3::new(5, 0, 1), Pnt3::new(1, 0, 3), Pnt3::new(0, 0, 2)));
faces.push(Pnt3::new(Pnt3::new(5, 1, 0), Pnt3::new(6, 1, 1), Pnt3::new(1, 1, 2)));
faces.push(Pnt3::new(Pnt3::new(6, 1, 1), Pnt3::new(2, 1, 3), Pnt3::new(1, 1, 2)));
faces.push(Pnt3::new(Pnt3::new(6, 2, 1), Pnt3::new(7, 2, 0), Pnt3::new(3, 2, 2)));
faces.push(Pnt3::new(Pnt3::new(2, 2, 3), Pnt3::new(6, 2, 1), Pnt3::new(3, 2, 2)));
faces.push(Pnt3::new(Pnt3::new(7, 3, 1), Pnt3::new(4, 3, 0), Pnt3::new(0, 3, 2)));
faces.push(Pnt3::new(Pnt3::new(3, 3, 3), Pnt3::new(7, 3, 1), Pnt3::new(0, 3, 2)));
faces.push(Pnt3::new(Pnt3::new(0, 4, 2), Pnt3::new(1, 4, 0), Pnt3::new(2, 4, 1)));
faces.push(Pnt3::new(Pnt3::new(3, 4, 3), Pnt3::new(0, 4, 2), Pnt3::new(2, 4, 1)));
faces.push(Pnt3::new(Pnt3::new(7, 5, 3), Pnt3::new(6, 5, 1), Pnt3::new(5, 5, 0)));
faces.push(Pnt3::new(Pnt3::new(4, 5, 2), Pnt3::new(7, 5, 3), Pnt3::new(5, 5, 0)));
TriMesh::new(coords, Some(normals), Some(uvs), Some(IndexBuffer::Split(faces)))
}
pub fn rectangle<P>(extents: &P::Vect) -> Polyline<P>
where P: Point {
let mut rectangle = unit_rectangle::<P>();
rectangle.scale_by(extents);
rectangle
}
pub fn unit_rectangle<P>() -> Polyline<P>
where P: Point {
let _0_5: <P::Vect as Vect>::Scalar = na::cast(0.5);
let m0_5: <P::Vect as Vect>::Scalar = -_0_5;
let mut p_ul = na::orig::<P>();
let mut p_ur = na::orig::<P>();
let mut p_dl = na::orig::<P>();
let mut p_dr = na::orig::<P>();
p_dl[0] = m0_5.clone(); p_dl[1] = m0_5.clone();
p_dr[0] = _0_5.clone(); p_dr[1] = m0_5.clone();
p_ur[0] = _0_5.clone(); p_ur[1] = _0_5.clone();
p_ul[0] = m0_5.clone(); p_ul[1] = _0_5.clone();
Polyline::new(vec!(p_ur, p_ul, p_dl, p_dr), None)
}