{I+=codeWee;}
[C++] Math: How to Calculate Inverse Matrix
struct Matrix4x4
{
public:
	union
	{
		struct
		{
			float        _11, _12, _13, _14;
			float        _21, _22, _23, _24;
			float        _31, _32, _33, _34;
			float        _41, _42, _43, _44;
		};
		struct
		{
			float        m1[4];
			float        m2[4];
			float        m3[4];
			float        m4[4];
		};
		float elements[4][4];
		float m[16];
	};
}


Matrix4x4 GetInverse()
{
	Matrix4x4 temp;
	float fDef = (_11*(_22*_33 - _23*_32)
		- _12*(_21*_33 - _23*_31))
		+ _13*(_21*_32 - _22*_31);
	float fDetInv = 1.0f / fDef;

	temp._11 = fDetInv*(_22*_33 - _23*_32);
	temp._21 = -fDetInv*(_21*_33 - _23*_31);
	temp._31 = fDetInv*(_21*_32 - _22*_31);

	temp._12 = -fDetInv*(_12*_33 - _13*_32);
	temp._22 = fDetInv*(_11*_33 - _13*_31);
	temp._32 = -fDetInv*(_11*_32 - _12*_31);

	temp._13 = fDetInv*(_12*_23 - _13*_22);
	temp._23 = -fDetInv*(_11*_23 - _13*_21);
	temp._33 = fDetInv*(_11*_22 - _12*_21);

	temp._41 = -(_41*temp._11 + _42*temp._21 + _43*temp._31);
	temp._42 = -(_41*temp._12 + _42*temp._22 + _43*temp._32);
	temp._43 = -(_41*temp._13 + _42*temp._23 + _43*temp._33);

	return temp;
}
HTML | PHP | C++ | DirectX11 | Javascript | C# | HTML5 | ASP | SQL | General | CSS | Oculus Rift | Unity3d | Virtools SDK | Tip | NSIS | PowerShell | node.js | Web API | RTSP | All
Copyright© 2016 CodeWee.com All rights reserved.