mirror of
https://github.com/guilhermewerner/wgpu-renderer
synced 2025-06-15 05:14:20 +00:00
25 lines
633 B
Rust
25 lines
633 B
Rust
use super::Camera;
|
|
use bytemuck::{Pod, Zeroable};
|
|
use cgmath::SquareMatrix;
|
|
|
|
// This is so we can store this in a buffer
|
|
#[repr(C)]
|
|
#[derive(Debug, Copy, Clone, Pod, Zeroable)]
|
|
pub struct CameraUniform {
|
|
// We can't use cgmath with bytemuck directly so we'll have
|
|
// to convert the Matrix4 into a 4x4 f32 array
|
|
pub view_proj: [[f32; 4]; 4],
|
|
}
|
|
|
|
impl CameraUniform {
|
|
pub fn New() -> Self {
|
|
Self {
|
|
view_proj: cgmath::Matrix4::identity().into(),
|
|
}
|
|
}
|
|
|
|
pub fn UpdateViewProjection(&mut self, camera: &Camera) {
|
|
self.view_proj = camera.BuildViewProjectionMatrix().into();
|
|
}
|
|
}
|