fromQuaternion method
Uses the given quaternion to transform the upper left 3x3 part to a rotation matrix. Other parts of the matrix are equal to the identiy matrix.
Implementation
Matrix4 fromQuaternion(Quaternion q ) {
final e = elements;
final x = q.x, y = q.y, z = q.z, w = q.w;
final x2 = x + x, y2 = y + y, z2 = z + z;
final xx = x * x2, xy = x * y2, xz = x * z2;
final yy = y * y2, yz = y * z2, zz = z * z2;
final wx = w * x2, wy = w * y2, wz = w * z2;
e[ 0 ] = 1 - ( yy + zz );
e[ 4 ] = xy - wz;
e[ 8 ] = xz + wy;
e[ 1 ] = xy + wz;
e[ 5 ] = 1 - ( xx + zz );
e[ 9 ] = yz - wx;
e[ 2 ] = xz - wy;
e[ 6 ] = yz + wx;
e[ 10 ] = 1 - ( xx + yy );
e[ 3 ] = 0;
e[ 7 ] = 0;
e[ 11 ] = 0;
e[ 12 ] = 0;
e[ 13 ] = 0;
e[ 14 ] = 0;
e[ 15 ] = 1;
return this;
}