File tree Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Expand file tree Collapse file tree 1 file changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -511,15 +511,28 @@ impl Collider {
511511 /// with a non-uniform scale results in an ellipse which isn’t supported),
512512 /// the shape is approximated by a convex polygon/convex polyhedron using
513513 /// `num_subdivisions` subdivisions.
514- pub fn set_scale ( & mut self , scale : Vect , num_subdivisions : u32 ) {
514+ pub fn set_scale ( & mut self , mut scale : Vect , num_subdivisions : u32 ) {
515+ /// We restrict the scaling increment to 1.0e-4, to avoid numerical jitter
516+ /// due to the extraction of scaling factor from the GlobalTransform matrix.
517+ fn snap_value ( new : & mut f32 ) {
518+ const PRECISION : f32 = 1.0e4 ;
519+ * new = ( * new * PRECISION ) . round ( ) / PRECISION ;
520+ }
521+
522+ snap_value ( & mut scale. x ) ;
523+ snap_value ( & mut scale. y ) ;
524+ #[ cfg( feature = "dim3" ) ]
525+ snap_value ( & mut scale. z ) ;
526+
515527 if scale == self . scale {
516528 // Nothing to do.
529+ return ;
517530 }
518531
519532 if scale == Vect :: ONE {
520533 // Trivial case.
521534 self . raw = self . unscaled . clone ( ) ;
522- self . scale = scale ;
535+ self . scale = Vect :: ONE ;
523536 return ;
524537 }
525538
You can’t perform that action at this time.
0 commit comments