Reset matrix to identity?

Is there a fast method to reset a matrix to identity?

use case is I want to mutably set a matrix to be just a translation, so to avoid the extra allocation here:

mat.copy_from(&Matrix4<f64>::identity());
mat.prepend_translation_mut(&translation);

Hi!

You can use mat.fill_with_identity() (doc).
By the way note that Matrix4::identity() won’t perform an allocation on the heap. Matrices with dimensions known at compile-time will reside on the stack.

1 Like