Skip to content

Commit a85325a

Browse files
yakkudevnot-fl3
authored andcommitted
added camera near and far fields
1 parent 8de643f commit a85325a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/camera.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ pub struct Camera3D {
198198
///
199199
/// Useful for things like splitscreen.
200200
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,
201206
}
202207

203208
impl Default for Camera3D {
@@ -211,29 +216,26 @@ impl Default for Camera3D {
211216
projection: Projection::Perspective,
212217
render_target: None,
213218
viewport: None,
219+
z_near: 0.01,
220+
z_far: 10000.0,
214221
}
215222
}
216223
}
217224

218-
impl Camera3D {
219-
const Z_NEAR: f32 = 0.01;
220-
const Z_FAR: f32 = 10000.0;
221-
}
222-
223225
impl Camera for Camera3D {
224226
fn matrix(&self) -> Mat4 {
225227
let aspect = self.aspect.unwrap_or(screen_width() / screen_height());
226228

227229
match self.projection {
228230
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)
230232
* Mat4::look_at_rh(self.position, self.target, self.up)
231233
}
232234
Projection::Orthographics => {
233235
let top = self.fovy / 2.0;
234236
let right = top * aspect;
235237

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)
237239
* Mat4::look_at_rh(self.position, self.target, self.up)
238240
}
239241
}

0 commit comments

Comments
 (0)