Matrix4x4f Matrix4x4f::scaleMatrix(const Vec3f &scale) { Matrix4x4f scaleMatrix; scaleMatrix.setIdentity(); scaleMatrix.set(0, 0, scale.x); scaleMatrix.set(1, 1, scale.y); scaleMatrix.set(2, 2, scale.z); return scaleMatrix; }
Matrix4x4f Matrix4x4f::translateMatrix(const Vec3f translation) { Matrix4x4f translateMatrix; translateMatrix.setIdentity(); translateMatrix.set(3, 0, translation.x); translateMatrix.set(3, 1, translation.y); translateMatrix.set(3, 2, translation.z); return translateMatrix; }
Matrix4x4f Matrix4x4f::rotateMatrixZ(float angle) { float cosOfAngle = std::cosf(angle); float sinOfAngle = std::sinf(angle); Matrix4x4f rotationMatrix; rotationMatrix.setIdentity(); rotationMatrix.set(0, 0, cosOfAngle); rotationMatrix.set(1, 0, sinOfAngle); rotationMatrix.set(0, 1, -sinOfAngle); rotationMatrix.set(1, 1, cosOfAngle); return rotationMatrix; }
Matrix4x4f Matrix4x4f::transpose() const { Matrix4x4f transpose; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) transpose.set(j, i, get(i, j)); return transpose; }
Matrix4x4f Matrix4x4f::operator*(const Matrix4x4f &other) const { Matrix4x4f product; for (int i = 0; i < 4; i++) for (int j = 0; j < 4; j++) { float sum = 0.0f; // jth row of this by ith column of other for (int d = 0; d < 4; d++) sum += get(d, j) * other.get(i, d); product.set(i, j, sum); } return product; }