Same near&far plane for cam and lights
This commit is contained in:
parent
b978091cd4
commit
e153ff5b6b
2 changed files with 7 additions and 4 deletions
|
@ -3,6 +3,9 @@ use std::time::Duration;
|
||||||
use cgmath::num_traits::clamp;
|
use cgmath::num_traits::clamp;
|
||||||
use winit::{dpi::PhysicalPosition, event::*};
|
use winit::{dpi::PhysicalPosition, event::*};
|
||||||
|
|
||||||
|
pub const NEAR_PLANE: f32 = 0.1;
|
||||||
|
pub const FAR_PLANE: f32 = 3000.0;
|
||||||
|
|
||||||
pub struct Camera {
|
pub struct Camera {
|
||||||
pub position: cgmath::Point3<f32>,
|
pub position: cgmath::Point3<f32>,
|
||||||
pub pitch: f32,
|
pub pitch: f32,
|
||||||
|
@ -42,8 +45,8 @@ impl Camera {
|
||||||
projection: PerspectiveProjection {
|
projection: PerspectiveProjection {
|
||||||
aspect,
|
aspect,
|
||||||
fovy,
|
fovy,
|
||||||
znear: 0.1,
|
znear: NEAR_PLANE,
|
||||||
zfar: 3000.0,
|
zfar: FAR_PLANE,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use std::ops::Range;
|
use std::ops::Range;
|
||||||
|
|
||||||
use super::model::{Mesh, Model};
|
use super::{model::{Mesh, Model}, camera::{NEAR_PLANE, FAR_PLANE}};
|
||||||
|
|
||||||
use cgmath::{Matrix4, Vector3};
|
use cgmath::{Matrix4, Vector3};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ pub struct LightUniform {
|
||||||
|
|
||||||
impl LightUniform {
|
impl LightUniform {
|
||||||
pub fn new(position: [f32; 3], color: [f32; 4]) -> Self {
|
pub fn new(position: [f32; 3], color: [f32; 4]) -> Self {
|
||||||
let proj = cgmath::perspective(cgmath::Deg(90.0), 1.0, 0.1, 1000.0);
|
let proj = cgmath::perspective(cgmath::Deg(90.0), 1.0, NEAR_PLANE, FAR_PLANE);
|
||||||
#[rustfmt::skip]
|
#[rustfmt::skip]
|
||||||
let matrices: [[[f32; 4]; 4]; 6] = [
|
let matrices: [[[f32; 4]; 4]; 6] = [
|
||||||
(proj * Matrix4::look_to_rh(position.into(), Vector3::new( 1.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 0.0))).into(),
|
(proj * Matrix4::look_to_rh(position.into(), Vector3::new( 1.0, 0.0, 0.0), Vector3::new(0.0, 1.0, 0.0))).into(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue