ray_tracing_core/math/
ortho_normal_base.rs1use crate::types::Vector3;
2
3pub struct OrthoNormalBase {
4 pub axis: [Vector3; 3],
5}
6
7impl OrthoNormalBase {
8 pub fn form_w(n: &Vector3) -> OrthoNormalBase {
9 let axis_z = glm::normalize(*n);
10 let a = if axis_z.x.abs() > 0.9 {
11 Vector3::new(0.0, 1.0, 0.0)
12 } else {
13 Vector3::new(1.0, 0.0, 0.0)
14 };
15 let axis_y = glm::normalize(glm::cross(axis_z, a));
16 let axis_x = glm::cross(axis_z, axis_y);
17 OrthoNormalBase {
18 axis: [axis_x, axis_y, axis_z],
19 }
20 }
21
22 pub fn u(&self) -> Vector3 {
23 self.axis[0]
24 }
25 pub fn v(&self) -> Vector3 {
26 self.axis[1]
27 }
28 pub fn w(&self) -> Vector3 {
29 self.axis[2]
30 }
31
32 pub fn local(&self, a: Vector3) -> Vector3 {
33 self.u() * a.x + self.v() * a.y + self.w() * a.z
34 }
35}