decompose method
Decomposes this into translation
, rotation
and scale
components.
Implementation
void decompose(Vector3 translation, Quaternion rotation, Vector3 scale) {
final Vector3 v = new Vector3.zero();
double sx =
(v..setValues(_m4storage[0], _m4storage[1], _m4storage[2])).length;
final double sy =
(v..setValues(_m4storage[4], _m4storage[5], _m4storage[6])).length;
final double sz =
(v..setValues(_m4storage[8], _m4storage[9], _m4storage[10])).length;
if (determinant() < 0) {
sx = -sx;
}
translation._v3storage[0] = _m4storage[12];
translation._v3storage[1] = _m4storage[13];
translation._v3storage[2] = _m4storage[14];
final double invSX = 1.0 / sx;
final double invSY = 1.0 / sy;
final double invSZ = 1.0 / sz;
final Matrix4 m = new Matrix4.copy(this);
m._m4storage[0] *= invSX;
m._m4storage[1] *= invSX;
m._m4storage[2] *= invSX;
m._m4storage[4] *= invSY;
m._m4storage[5] *= invSY;
m._m4storage[6] *= invSY;
m._m4storage[8] *= invSZ;
m._m4storage[9] *= invSZ;
m._m4storage[10] *= invSZ;
rotation.setFromRotation(m.getRotation());
scale._v3storage[0] = sx;
scale._v3storage[1] = sy;
scale._v3storage[2] = sz;
}