use cgmath::{Point3, Vector3, Matrix4, Deg, InnerSpace, Zero}; pub struct Camera { position: Point3, proj_matrix: Matrix4, view_matrix: Matrix4 } impl Camera { pub fn new(aspect: f32) -> Self { let mut instance = Self { position: (2.0,1.0,2.0).into(), view_matrix: Matrix4::look_to_rh( (0.0,0.0,0.0).into(), Vector3{ x:0.66, y:0.0, z:0.66}.normalize(), Vector3::unit_y() ), proj_matrix: Matrix4::zero() }; instance.set_aspect(aspect); instance } pub fn set_aspect(&mut self, aspect: f32) { self.proj_matrix = cgmath::perspective(Deg(60.0), aspect, 0.1, 100.0); } pub fn get_projection(&self) -> Matrix4 { self.proj_matrix } pub fn get_view(&self) -> Matrix4 { self.view_matrix } pub fn get_position(&self) -> Point3 { self.position } } pub trait CameraTransform { fn update(&mut self, position: Point3, forward: Vector3, up: Vector3); } impl CameraTransform for Camera { fn update(&mut self, position: Point3, forward: Vector3, up: Vector3) { self.position = position; self.view_matrix = Matrix4::look_to_rh((0.0,0.0,0.0).into(), forward, up); } }