예제 #1
0
void bbe::Mat3x3::inverse()
{
	float det =  valeurs[0] * (valeurs[4] * valeurs[8] - valeurs[7] * valeurs[5])
		- valeurs[1] * (valeurs[3] * valeurs[8] - valeurs[6] * valeurs[5])
		+ valeurs[2] * (valeurs[3] * valeurs[7] - valeurs[6] * valeurs[4]);

	if(fabs(det) < 0.0005)
	{
		return;
	}
	float newmat[9];	

	newmat[0] =   valeurs[4] * valeurs[8] - valeurs[5] * valeurs[7]  / det;
	newmat[1] = -(valeurs[1] * valeurs[8] - valeurs[7] * valeurs[2]) / det;
	newmat[2] =   valeurs[1] * valeurs[5] - valeurs[4] * valeurs[2]  / det;

	newmat[3] = -(valeurs[3] * valeurs[8] - valeurs[5] * valeurs[6]) / det;
	newmat[4] =   valeurs[0] * valeurs[8] - valeurs[6] * valeurs[2]  / det;
	newmat[5] = -(valeurs[0] * valeurs[5] - valeurs[3] * valeurs[2]) / det;

	newmat[6] =   valeurs[3] * valeurs[7] - valeurs[6] * valeurs[4]  / det;
	newmat[7] = -(valeurs[0] * valeurs[7] - valeurs[6] * valeurs[1]) / det;
	newmat[8] =   valeurs[0] * valeurs[4] - valeurs[1] * valeurs[3]  / det;
	

	*this = Mat3x3(newmat);
}
Mat3x3 Mat3x3::operator*(const float _value) const
{
    return Mat3x3(entries[0] * _value,
            entries[1] * _value,
            entries[2] * _value,
            entries[3] * _value,
            entries[4] * _value,
            entries[5] * _value,
            entries[6] * _value,
            entries[7] * _value,
            entries[8] * _value);
}
Mat3x3 Mat3x3::operator -(const Mat3x3 & _value) const
{
    return Mat3x3(entries[0] - _value.entries[0],
            entries[1] - _value.entries[1],
            entries[2] - _value.entries[2],
            entries[3] - _value.entries[3],
            entries[4] - _value.entries[4],
            entries[5] - _value.entries[5],
            entries[6] - _value.entries[6],
            entries[7] - _value.entries[7],
            entries[8] - _value.entries[8]);

}
Mat3x3 Mat3x3::operator+(const Mat3x3 & _value) const
{
    return Mat3x3(entries[0] + _value.entries[0],
            entries[1] + _value.entries[1],
            entries[2] + _value.entries[2],
            entries[3] + _value.entries[3],
            entries[4] + _value.entries[4],
            entries[5] + _value.entries[5],
            entries[6] + _value.entries[6],
            entries[7] + _value.entries[7],
            entries[8] + _value.entries[8]);

}
예제 #5
0
	//Transform matrix by X and Y
	Mat3x3 Mat3x3::TransformMat3(float xChange, float yChange, Mat3x3 &otherMatrix)
	{
		//Create change matrix
		std::vector<std::vector<float>> changeMatrix =
		{
			{ 1, 0, 0 },
			{ 0, 1, 0 },
			{ xChange, yChange, 1 }
		};

		//Turn change matrix into a mat3x3
		Mat3x3 ChangeMat = Mat3x3(changeMatrix);

		//Multiply and return the result
		return ChangeMat * otherMatrix;
	}
예제 #6
0
	//Rotate Mat3x3 on the Z-axis by x degrees
	Mat3x3 Mat3x3::RotMat3_Z(float degreeChange, Mat3x3 &otherMatrix)
	{
		//Create change matrix
		std::vector<std::vector<float>> changeMatrix =
		{
			{ (cos(degreeChange)), (sin(degreeChange)), 0 },
			{ (asin(degreeChange)), (cos(degreeChange)), 0 },
			{ 0, 0, 1 }
		};

		//Turn change matrix into a mat3x3
		Mat3x3 ChangeMat = Mat3x3(changeMatrix);

		//Multiply and return the result
		return ChangeMat * otherMatrix;
	}