@@ -19,25 +19,31 @@ pub const OPENGL_TO_WGPU_MATRIX: cgmath::Matrix4<f32> = cgmath::Matrix4::new(
1919pub struct CameraUniform {
2020 // We can't use cgmath with bytemuck directly so we'll have
2121 // to convert the Matrix4 into a 4x4 f32 array
22- view_proj : [ [ f32 ; 4 ] ; 4 ] ,
22+ view : [ [ f32 ; 4 ] ; 4 ] ,
23+ proj : [ [ f32 ; 4 ] ; 4 ] ,
2324}
2425
2526impl CameraUniform {
2627 pub fn new ( ) -> Self {
2728 Self {
28- view_proj : cgmath:: Matrix4 :: identity ( ) . into ( ) ,
29+ view : cgmath:: Matrix4 :: identity ( ) . into ( ) ,
30+ proj : cgmath:: Matrix4 :: identity ( ) . into ( ) ,
2931 }
3032 }
3133
32- pub fn update_view_proj ( & mut self , matrix : cgmath:: Matrix4 < f32 > ) {
33- self . view_proj = matrix. into ( ) ;
34+ pub fn update_proj ( & mut self , matrix : cgmath:: Matrix4 < f32 > ) {
35+ self . proj = matrix. into ( ) ;
36+ }
37+
38+ pub fn update_view ( & mut self , matrix : cgmath:: Matrix4 < f32 > ) {
39+ self . view = matrix. into ( ) ;
3440 }
3541
3642 pub fn desc ( ) -> wgpu:: BindGroupLayoutDescriptor < ' static > {
3743 wgpu:: BindGroupLayoutDescriptor {
3844 entries : & [ wgpu:: BindGroupLayoutEntry {
3945 binding : 0 ,
40- visibility : wgpu:: ShaderStages :: VERTEX ,
46+ visibility : wgpu:: ShaderStages :: VERTEX_FRAGMENT ,
4147 ty : wgpu:: BindingType :: Buffer {
4248 ty : wgpu:: BufferBindingType :: Uniform ,
4349 has_dynamic_offset : false ,
@@ -123,8 +129,9 @@ impl OrbitCamera {
123129 let pos = cgmath:: Point3 :: from_vec ( pos. to_vec ( ) + self . target . to_vec ( ) ) ;
124130
125131 let view = cgmath:: Matrix4 :: look_at_rh ( pos, self . target , self . up ) ;
126- let projection_matrix = OPENGL_TO_WGPU_MATRIX * proj * view;
127- self . uniform . update_view_proj ( projection_matrix) ;
132+ let projection_matrix = OPENGL_TO_WGPU_MATRIX * proj;
133+ self . uniform . update_proj ( projection_matrix) ;
134+ self . uniform . update_view ( view) ;
128135 context
129136 . queue ( )
130137 . write_buffer ( & self . buffer , 0 , bytemuck:: cast_slice ( & [ self . uniform ] ) ) ;
0 commit comments