D3DXMATRIX R, T, M;
D3DXMatrixTranslation(&T, 2.0f, 0.0f, 0.0f);
D3DXMatrixInverse(&M, NULL, &M);
float r=GetYRotation(&M); // the helper I want to make
// if it worked properly it would do this:
// r would equel pi*0.5
if the M matrix will always be Y rotation matrix, you could derive the parameter it is constructed from just as this : acos (M).
But this parameter is not an angle with Y axis - it is actualy an angle in ZX plane - thus making objects revolve around Y axis if transfomed by M.
But if you will incompose also Z and X rotation matricies into the M matrix (multiply the M with them), then you will not be able to use this simple solution. You will need to solve 3 linear equations. I recomend Cramer method for solving them as it does not use division, so you will be zero safe. Following is a method that constructs world rotation and translation from the 3 axises sinuses and cosinuses and position
the res is a 16 array in column memory layout (resis 4th component of first column) and cx,cy,cz,sx,sy,sz are cosinuses of X,Y,Z and sinuses of X,Y,Z angles respectively
Now if you look at it you may take equations as those:
you should find out cy through third simple equation m3=-sy such as sqrt(1.0-asin(-1.0*m3)) and use 2 linear equations system only:
M=cx*cy; where cy is aleary existing constant you computed
this is cramer's rule
Consider a system of n linear equations for n unknowns, represented in matrix multiplication form as follows:
where the n by n matrix has a nonzero determinant, and the vector is the column vector of the variables.
Then the theorem states that in this case the system has a unique solution, whose individual values for the unknowns are given by:
where is the matrix formed by replacing the ith column of by the column vector .
So you would perform b column to be M[0,0],M[2,2] and A matrix to be
you then compute x1 and x2 by applying last sentence of quoted Cramer's rule on them both. You will then poses cx,cy,cz and use acos on all three to know angles around all three axises of a rotation matrix