GRIM: Fix matrix to quaternion conversion. Fixes #1132

The previous rotation matrix to quaternion conversion method did not always produce a quaternion of length 1. This fixes that.