fromRotation function

List<double>? fromRotation(
  1. List<double> out,
  2. double rad,
  3. List<double> axis
)

Creates a matrix from a given angle around a given axis This is equivalent to (but much faster than):

mat4.identity(dest);
mat4.rotate(dest, dest, double rad, axis);

@param {mat4} out mat4 receiving operation result @param {Number} rad the angle to rotate the matrix by @param {ReadonlyVec3} axis the axis to rotate around @returns {mat4} out

Implementation

List<double>? fromRotation(List<double> out, double rad, List<double> axis) {
  double x = axis[0], y = axis[1], z = axis[2];
  double len = hypot([x, y, z]);
  double s, c, t;

  if (len < GlMatrix.EPSILON) {
    return null;
  }

  len = 1 / len;
  x *= len;
  y *= len;
  z *= len;

  s = math.sin(rad);
  c = math.cos(rad);
  t = 1 - c;

  // Perform rotation-specific matrix multiplication
  out[0] = x * x * t + c;
  out[1] = y * x * t + z * s;
  out[2] = z * x * t - y * s;
  out[3] = 0;
  out[4] = x * y * t - z * s;
  out[5] = y * y * t + c;
  out[6] = z * y * t + x * s;
  out[7] = 0;
  out[8] = x * z * t + y * s;
  out[9] = y * z * t - x * s;
  out[10] = z * z * t + c;
  out[11] = 0;
  out[12] = 0;
  out[13] = 0;
  out[14] = 0;
  out[15] = 1;
  return out;
}