camera: Try fix camera
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m5s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m5s
This commit is contained in:
parent
a0fce9c08e
commit
09bfe6fb48
2 changed files with 79 additions and 34 deletions
|
@ -1,6 +1,6 @@
|
|||
use std::sync::Arc;
|
||||
|
||||
use glam::Mat4;
|
||||
use glam::{EulerRot, Mat4, Quat, Vec3};
|
||||
use vulkano::{
|
||||
Validated,
|
||||
buffer::{AllocateBufferError, Subbuffer},
|
||||
|
@ -14,7 +14,8 @@ pub struct Camera {
|
|||
view: Mat4,
|
||||
projection: Mat4,
|
||||
|
||||
transform: Transform,
|
||||
position: Vec3,
|
||||
rotation: Vec3,
|
||||
}
|
||||
|
||||
impl Camera {
|
||||
|
@ -22,27 +23,53 @@ impl Camera {
|
|||
Self {
|
||||
view,
|
||||
projection,
|
||||
transform: Transform::default(),
|
||||
position: Vec3::ZERO,
|
||||
rotation: Vec3::ZERO,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_transform(&self) -> &Transform {
|
||||
&self.transform
|
||||
pub fn rotate(&mut self, rotation: Vec3) {
|
||||
self.rotation += rotation;
|
||||
}
|
||||
|
||||
pub fn get_transform_mut(&mut self) -> &mut Transform {
|
||||
&mut self.transform
|
||||
pub fn translate(&mut self, translation: Vec3) {
|
||||
self.position += translation;
|
||||
}
|
||||
|
||||
pub fn set_view(&mut self, view: Mat4) {
|
||||
self.view = view;
|
||||
}
|
||||
|
||||
pub fn set_projection(&mut self, projection: Mat4) {
|
||||
self.projection = projection;
|
||||
}
|
||||
|
||||
pub fn get_rotation(&self) -> Vec3 {
|
||||
self.rotation
|
||||
}
|
||||
|
||||
pub fn set_rotation(&mut self, rotation: Vec3) {
|
||||
self.rotation = rotation;
|
||||
}
|
||||
|
||||
pub fn get_position(&self) -> Vec3 {
|
||||
self.position
|
||||
}
|
||||
|
||||
pub fn set_position(&mut self, position: Vec3) {
|
||||
self.position = position;
|
||||
}
|
||||
|
||||
pub fn create_buffer(
|
||||
&self,
|
||||
memory_allocator: &Arc<StandardMemoryAllocator>,
|
||||
) -> Result<Subbuffer<[MVP]>, Validated<AllocateBufferError>> {
|
||||
MVP::new(&self.transform.get_mat4(), &self.view, &self.projection)
|
||||
.into_buffer(memory_allocator)
|
||||
let mut world_matrix = Mat4::IDENTITY;
|
||||
world_matrix *= Mat4::from_quat(Quat::from_rotation_z(self.rotation.z));
|
||||
world_matrix *= Mat4::from_quat(Quat::from_rotation_y(self.rotation.y));
|
||||
world_matrix *= Mat4::from_quat(Quat::from_rotation_x(self.rotation.x));
|
||||
world_matrix *= Mat4::from_translation(-self.position);
|
||||
|
||||
MVP::new(&world_matrix, &self.view, &self.projection).into_buffer(memory_allocator)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue