@@ -10,6 +10,17 @@ use crate::math::{
1010 matrix:: Matrix ,
1111} ;
1212
13+ /// Build a 4x4 uniform scaling matrix with `uniform_scale` on the diagonal
14+ /// and `1.0` in the homogeneous component.
15+ fn scaling_matrix ( uniform_scale : f32 ) -> [ [ f32 ; 4 ] ; 4 ] {
16+ return [
17+ [ uniform_scale, 0.0 , 0.0 , 0.0 ] ,
18+ [ 0.0 , uniform_scale, 0.0 , 0.0 ] ,
19+ [ 0.0 , 0.0 , uniform_scale, 0.0 ] ,
20+ [ 0.0 , 0.0 , 0.0 , 1.0 ] ,
21+ ] ;
22+ }
23+
1324/// Convert OpenGL-style normalized device coordinates (Z in [-1, 1]) to
1425/// wgpu/Vulkan/Direct3D normalized device coordinates (Z in [0, 1]).
1526///
@@ -48,17 +59,7 @@ pub fn compute_model_matrix(
4859 let mut model: [ [ f32 ; 4 ] ; 4 ] = matrix:: identity_matrix ( 4 , 4 ) ;
4960 // Apply rotation first, then scaling via a diagonal matrix, and finally translation.
5061 model = matrix:: rotate_matrix ( model, rotation_axis, angle_in_turns) ;
51-
52- let mut scaled: [ [ f32 ; 4 ] ; 4 ] = [ [ 0.0 ; 4 ] ; 4 ] ;
53- for i in 0 ..4 {
54- for j in 0 ..4 {
55- if i == j {
56- scaled[ i] [ j] = if i == 3 { 1.0 } else { uniform_scale } ;
57- } else {
58- scaled[ i] [ j] = 0.0 ;
59- }
60- }
61- }
62+ let scaled = scaling_matrix ( uniform_scale) ;
6263 model = model. multiply ( & scaled) ;
6364
6465 let translation_matrix: [ [ f32 ; 4 ] ; 4 ] =
0 commit comments