@@ -198,6 +198,11 @@ pub struct Camera3D {
198
198
///
199
199
/// Useful for things like splitscreen.
200
200
pub viewport : Option < ( i32 , i32 , i32 , i32 ) > ,
201
+
202
+ /// Camera near plane
203
+ pub z_near : f32 ,
204
+ /// Camera far plane
205
+ pub z_far : f32 ,
201
206
}
202
207
203
208
impl Default for Camera3D {
@@ -211,29 +216,26 @@ impl Default for Camera3D {
211
216
projection : Projection :: Perspective ,
212
217
render_target : None ,
213
218
viewport : None ,
219
+ z_near : 0.01 ,
220
+ z_far : 10000.0 ,
214
221
}
215
222
}
216
223
}
217
224
218
- impl Camera3D {
219
- const Z_NEAR : f32 = 0.01 ;
220
- const Z_FAR : f32 = 10000.0 ;
221
- }
222
-
223
225
impl Camera for Camera3D {
224
226
fn matrix ( & self ) -> Mat4 {
225
227
let aspect = self . aspect . unwrap_or ( screen_width ( ) / screen_height ( ) ) ;
226
228
227
229
match self . projection {
228
230
Projection :: Perspective => {
229
- Mat4 :: perspective_rh_gl ( self . fovy , aspect, Self :: Z_NEAR , Self :: Z_FAR )
231
+ Mat4 :: perspective_rh_gl ( self . fovy , aspect, self . z_near , self . z_far )
230
232
* Mat4 :: look_at_rh ( self . position , self . target , self . up )
231
233
}
232
234
Projection :: Orthographics => {
233
235
let top = self . fovy / 2.0 ;
234
236
let right = top * aspect;
235
237
236
- Mat4 :: orthographic_rh_gl ( -right, right, -top, top, Self :: Z_NEAR , Self :: Z_FAR )
238
+ Mat4 :: orthographic_rh_gl ( -right, right, -top, top, self . z_near , self . z_far )
237
239
* Mat4 :: look_at_rh ( self . position , self . target , self . up )
238
240
}
239
241
}
0 commit comments