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
mod orthographic;
mod perspective;
pub use self::{orthographic::Orthographic, perspective::Perspective};
use {
crate::math::{vec3, vec4_from_vec3, Cone, Mat4, Sphere, Vec3},
std::ops::Range,
};
pub trait Camera {
fn depth(&self) -> &Range<f32>;
fn overlaps_cone(&self, cone: Cone) -> bool;
fn overlaps_point(&self, p: Vec3) -> bool;
fn overlaps_sphere(&self, sphere: Sphere) -> bool;
fn eye(&self) -> Vec3;
fn project_point(&self, p: Vec3) -> Vec3;
fn projection(&self) -> Mat4;
fn unproject_point(&self, p: Vec3) -> Vec3;
fn view(&self) -> Mat4;
fn view_inv(&self) -> Mat4;
fn corners(&self) -> [Vec3; 8] {
let view_inv = self.view_inv();
const P: f32 = 1.0;
const N: f32 = -1.0;
[
(view_inv * vec4_from_vec3(self.unproject_point(vec3(N, N, N)), 1.0)).truncate(),
(view_inv * vec4_from_vec3(self.unproject_point(vec3(N, N, P)), 1.0)).truncate(),
(view_inv * vec4_from_vec3(self.unproject_point(vec3(N, P, N)), 1.0)).truncate(),
(view_inv * vec4_from_vec3(self.unproject_point(vec3(N, P, P)), 1.0)).truncate(),
(view_inv * vec4_from_vec3(self.unproject_point(vec3(P, N, N)), 1.0)).truncate(),
(view_inv * vec4_from_vec3(self.unproject_point(vec3(P, N, P)), 1.0)).truncate(),
(view_inv * vec4_from_vec3(self.unproject_point(vec3(P, P, N)), 1.0)).truncate(),
(view_inv * vec4_from_vec3(self.unproject_point(vec3(P, P, P)), 1.0)).truncate(),
]
}
}
#[derive(Clone, Copy)]
enum Category {
X(bool),
Y(bool),
Z(bool),
}
impl Category {
fn is_sign_positive(self) -> bool {
match self {
Self::X(res) | Self::Y(res) | Self::Z(res) => res,
}
}
}
#[cfg(test)]
mod test {
#[test]
fn test_camera_corners() {
}
}