Matrix3x3f Matrix3x3f::RotateMatrix(float angle) { float cosOfAngle = cosf(angle); float sinOfAngle = sinf(angle); Matrix3x3f 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; }
Matrix3x3f Matrix3x3f::Transpose() const { Matrix3x3f transpose; for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) transpose.Set(j, i, Get(i, j)); return transpose; }
Matrix3x3f Matrix3x3f::TranslateMatrix(const Vec2f translation) { Matrix3x3f translateMatrix; translateMatrix.SetIdentity(); translateMatrix.Set(2, 0, translation.x); translateMatrix.Set(2, 1, translation.y); return translateMatrix; }
Matrix3x3f Matrix3x3f::ScaleMatrix(const Vec2f &scale) { Matrix3x3f scaleMatrix; scaleMatrix.SetIdentity(); scaleMatrix.Set(0, 0, scale.x); scaleMatrix.Set(1, 1, scale.y); return scaleMatrix; }
Matrix3x3f Matrix3x3f::operator*(const Matrix3x3f &other) const { Matrix3x3f product; for(int i = 0; i < 3; i++) for(int j = 0; j < 3; j++) { float sum = 0.0f; // jth row of this by ith column of other for(int d = 0; d < 3; d++) sum += Get(d, j) * other.Get(i, d); product.Set(i, j, sum); } return product; }