pointMatrixMult static method

Vector3 pointMatrixMult(
  1. Vector3 p1,
  2. Matrix4 matrix
)

Implementation

static Vector3 pointMatrixMult(Vector3 p1, Matrix4 matrix) {
  Vector3 res = Vector3.zero();
  res.x = p1.x * matrix[0] + p1.y * matrix[4] + p1.z * matrix[8] + matrix[12];
  res.y = p1.x * matrix[1] + p1.y * matrix[5] + p1.z * matrix[9] + matrix[13];
  res.z =
      p1.x * matrix[2] + p1.y * matrix[6] + p1.z * matrix[10] + matrix[14];
  double factor =
      p1.x * matrix[3] + p1.y * matrix[7] + p1.z * matrix[11] + matrix[15];
  if (factor != 1) {
    res.x /= factor;
    res.y /= factor;
    res.z /= factor;
  }
  return res;
}