rotateX function

List<double> rotateX(
  1. List<double> out,
  2. List<double> a,
  3. double rad
)

Rotates a matrix by the given angle around the X axis

@param {mat4} out the receiving matrix @param {ReadonlyMat4} a the matrix to rotate @param {Number} rad the angle to rotate the matrix by @returns {mat4} out

Implementation

List<double> rotateX(List<double> out, List<double> a, double rad) {
  final s = math.sin(rad);
  final c = math.cos(rad);
  final a10 = a[4];
  final a11 = a[5];
  final a12 = a[6];
  final a13 = a[7];
  final a20 = a[8];
  final a21 = a[9];
  final a22 = a[10];
  final a23 = a[11];

  if (a != out) {
    // If the source and destination differ, copy the unchanged rows
    out[0] = a[0];
    out[1] = a[1];
    out[2] = a[2];
    out[3] = a[3];
    out[12] = a[12];
    out[13] = a[13];
    out[14] = a[14];
    out[15] = a[15];
  }

  // Perform axis-specific matrix multiplication
  out[4] = a10 * c + a20 * s;
  out[5] = a11 * c + a21 * s;
  out[6] = a12 * c + a22 * s;
  out[7] = a13 * c + a23 * s;
  out[8] = a20 * c - a10 * s;
  out[9] = a21 * c - a11 * s;
  out[10] = a22 * c - a12 * s;
  out[11] = a23 * c - a13 * s;
  return out;
}