project structure cleanup
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
use cgmath::{Point3, Vector3, Matrix4, Deg};
|
||||
|
||||
pub struct Camera {
|
||||
pub position: Point3<f32>,
|
||||
pub forward: Vector3<f32>,
|
||||
pub up: Vector3<f32>,
|
||||
aspect: f32,
|
||||
fovy: f32,
|
||||
znear: f32,
|
||||
zfar: f32,
|
||||
}
|
||||
|
||||
impl Camera {
|
||||
|
||||
pub fn new(aspect: f32, fov: f32) -> Self {
|
||||
Self {
|
||||
position: (0.0, 1.0, 0.0).into(),
|
||||
forward: (0.0, 0.0, 1.0).into(),
|
||||
up: Vector3::unit_y(),
|
||||
aspect,
|
||||
fovy: fov,
|
||||
znear: 0.1,
|
||||
zfar: 100.0
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_aspect(&mut self, aspect: f32) {
|
||||
self.aspect = aspect;
|
||||
}
|
||||
|
||||
pub fn proj_matrix(&self) -> Matrix4<f32> {
|
||||
return cgmath::perspective(Deg(self.fovy), self.aspect, self.znear, self.zfar);
|
||||
}
|
||||
|
||||
pub fn view_matrix(&self) -> Matrix4<f32> {
|
||||
return Matrix4::look_to_rh((0.0,0.0,0.0).into(), self.forward, self.up);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user