@@ -39,13 +39,13 @@ pub struct Sphere {
39
39
40
40
impl Sphere {
41
41
/// Get a reference to the sphere's origin.
42
- pub fn origin ( & self ) -> & Vec3 {
43
- & self . origin
42
+ pub fn origin ( & self ) -> Vec3 {
43
+ self . origin
44
44
}
45
45
46
46
/// Get a reference to the sphere's radius.
47
- pub fn radius ( & self ) -> & f32 {
48
- & self . radius
47
+ pub fn radius ( & self ) -> f32 {
48
+ self . radius
49
49
}
50
50
51
51
/// Set the sphere's origin.
@@ -62,29 +62,29 @@ impl Primitive3d for Sphere {
62
62
/// Use the sphere's position and radius to determin eif it is entirely on the outside of the
63
63
/// the supplied plane.
64
64
fn outside_plane ( & self , plane : Plane ) -> bool {
65
- plane. distance_to_point ( & self . origin ) > self . radius
65
+ plane. distance_to_point ( self . origin ) > self . radius
66
66
}
67
67
}
68
68
69
69
/// An oriented box, unlike an axis aligned box, can be rotated and is not constrained to match the
70
70
/// orientation of the coordinate system it is defined in. Internally, this is represented as an
71
71
/// axis aligned box with some rotation ([Quat]) applied.
72
72
#[ derive( Copy , Clone , PartialEq , Debug , Reflect ) ]
73
- pub struct OrientedBox {
74
- aab : AxisAlignedBox ,
73
+ pub struct OBB {
74
+ aab : AABB ,
75
75
transform : Mat4 ,
76
76
}
77
- impl Primitive3d for OrientedBox {
77
+ impl Primitive3d for OBB {
78
78
fn outside_plane ( & self , plane : Plane ) -> bool {
79
79
for vertex in self . vertices ( ) . iter ( ) {
80
- if plane. distance_to_point ( vertex) <= 0.0 {
80
+ if plane. distance_to_point ( * vertex) <= 0.0 {
81
81
return false ;
82
82
}
83
83
}
84
84
true
85
85
}
86
86
}
87
- impl OrientedBox {
87
+ impl OBB {
88
88
/// An ordered list of the vertices that form the 8 corners of the [AxisAlignedBox].
89
89
/// ```none
90
90
/// (5)------(1)
@@ -105,15 +105,15 @@ impl OrientedBox {
105
105
}
106
106
107
107
/// Set the oriented box's aab.
108
- pub fn set_aab ( & mut self , aab : AxisAlignedBox ) {
108
+ pub fn set_aabb ( & mut self , aab : AABB ) {
109
109
self . aab = aab;
110
110
}
111
111
112
112
/// Set the oriented box's transform.
113
113
pub fn set_transform ( & mut self , transform : Mat4 ) {
114
114
self . transform = transform;
115
115
}
116
- pub fn fast_aabb ( & self ) -> AxisAlignedBox {
116
+ pub fn fast_aabb ( & self ) -> AABB {
117
117
let vertices = self . vertices ( ) ;
118
118
let mut max = Vec3 :: splat ( f32:: MIN ) ;
119
119
let mut min = Vec3 :: splat ( f32:: MAX ) ;
@@ -122,18 +122,18 @@ impl OrientedBox {
122
122
min = vertex. min ( min) ;
123
123
}
124
124
// Unwrap is okay here because min < max
125
- AxisAlignedBox :: from_min_max ( min, max) . unwrap ( )
125
+ AABB :: from_min_max ( min, max) . unwrap ( )
126
126
}
127
127
}
128
128
129
129
/// An axis aligned box is a box whose axes lie in the x/y/z directions of the coordinate system
130
130
/// the box is defined in.
131
131
#[ derive( Copy , Clone , PartialEq , Debug , Reflect ) ]
132
- pub struct AxisAlignedBox {
132
+ pub struct AABB {
133
133
min : Vec3 ,
134
134
max : Vec3 ,
135
135
}
136
- impl Primitive3d for AxisAlignedBox {
136
+ impl Primitive3d for AABB {
137
137
fn outside_plane ( & self , plane : Plane ) -> bool {
138
138
for vertex in self . vertices ( ) . iter ( ) {
139
139
if plane. distance_to_point ( vertex) <= 0.0 {
@@ -143,7 +143,7 @@ impl Primitive3d for AxisAlignedBox {
143
143
true
144
144
}
145
145
}
146
- impl AxisAlignedBox {
146
+ impl AABB {
147
147
/// An ordered list of the vertices that form the 8 corners of the [AxisAlignedBox].
148
148
/// ```none
149
149
/// (5)------(1) Y
@@ -169,21 +169,18 @@ impl AxisAlignedBox {
169
169
]
170
170
}
171
171
/// Construct an [AxisAlignedBox] given the coordinates of the minimum and maximum corners.
172
- pub fn from_min_max ( min : Vec3 , max : Vec3 ) -> Result < AxisAlignedBox , PrimitiveError > {
172
+ pub fn from_min_max ( min : Vec3 , max : Vec3 ) -> Result < AABB , PrimitiveError > {
173
173
if ( max - min) . min_element ( ) >= 0.0 {
174
- Ok ( AxisAlignedBox { min, max } )
174
+ Ok ( AABB { min, max } )
175
175
} else {
176
176
Err ( PrimitiveError :: MinGreaterThanMax )
177
177
}
178
178
}
179
179
/// Construct an [AxisALignedBox] from the origin at the minimum corner, and the extents - the
180
180
/// dimensions of the box in each axis.
181
- pub fn from_extents_origin (
182
- extents : Vec3 ,
183
- origin : Vec3 ,
184
- ) -> Result < AxisAlignedBox , PrimitiveError > {
181
+ pub fn from_extents_origin ( extents : Vec3 , origin : Vec3 ) -> Result < AABB , PrimitiveError > {
185
182
if extents. min_element ( ) > 0.0 {
186
- Ok ( AxisAlignedBox {
183
+ Ok ( AABB {
187
184
min : origin,
188
185
max : extents + origin,
189
186
} )
@@ -192,15 +189,15 @@ impl AxisAlignedBox {
192
189
}
193
190
}
194
191
/// Computes the AAB that
195
- pub fn from_points ( points : Vec < Vec3 > ) -> AxisAlignedBox {
192
+ pub fn from_points ( points : & [ Vec3 ] ) -> AABB {
196
193
let mut max = Vec3 :: splat ( f32:: MIN ) ;
197
194
let mut min = Vec3 :: splat ( f32:: MAX ) ;
198
195
for & point in points. iter ( ) {
199
196
max = point. max ( max) ;
200
197
min = point. min ( min) ;
201
198
}
202
199
// Unwrap is okay here because min < max
203
- AxisAlignedBox :: from_min_max ( min, max) . unwrap ( )
200
+ AABB :: from_min_max ( min, max) . unwrap ( )
204
201
}
205
202
}
206
203
@@ -223,8 +220,8 @@ impl Primitive3d for Frustum {
223
220
}
224
221
}
225
222
impl Frustum {
226
- fn compute_vertices ( camera_position : Mat4 , projection_matrix : Mat4 ) -> [ Vec3 ; 8 ] {
227
- let ndc_to_world: Mat4 = camera_position * projection_matrix. inverse ( ) ;
223
+ fn compute_vertices ( camera_position : & Mat4 , projection_matrix : & Mat4 ) -> [ Vec3 ; 8 ] {
224
+ let ndc_to_world: Mat4 = * camera_position * projection_matrix. inverse ( ) ;
228
225
[
229
226
ndc_to_world. project_point3 ( Vec3 :: new ( -1.0 , -1.0 , -1.0 ) ) ,
230
227
ndc_to_world. project_point3 ( Vec3 :: new ( 1.0 , -1.0 , -1.0 ) ) ,
@@ -237,7 +234,7 @@ impl Frustum {
237
234
]
238
235
}
239
236
240
- pub fn from_camera_properties ( camera_position : Mat4 , projection_matrix : Mat4 ) -> Frustum {
237
+ pub fn from_camera_properties ( camera_position : & Mat4 , projection_matrix : & Mat4 ) -> Frustum {
241
238
let vertices = Frustum :: compute_vertices ( camera_position, projection_matrix) ;
242
239
let [ nbl_world, nbr_world, ntl_world, ntr_world, fbl_world, fbr_world, ftl_world, ftr_world] =
243
240
vertices;
@@ -343,8 +340,8 @@ impl Plane {
343
340
/// Returns the nearest distance from the supplied point to this plane. Positive values are in
344
341
/// the direction of the plane's normal (outside), negative values are opposite the direction
345
342
/// of the planes normal (inside).
346
- pub fn distance_to_point ( & self , point : & Vec3 ) -> f32 {
347
- self . normal . dot ( * point) + -self . normal . dot ( self . point )
343
+ pub fn distance_to_point ( & self , point : Vec3 ) -> f32 {
344
+ self . normal . dot ( point) + -self . normal . dot ( self . point )
348
345
}
349
346
350
347
/// Get a reference to the plane's point.
0 commit comments