[ODE] dBodyGetRotation

Andrzej Szombierski qq at kuku.eu.org
Thu Aug 19 15:41:54 MST 2004


On Thu, 19 Aug 2004, Liu wrote:

> I create a body. I must get this body's rotation of x- , y-, z-axis.
> I use dBodyGetRotation get the matrix, but i must get the axis rotation, How should I do it ? thanks a lot ...

You need to extract the "euler angles" from the matrix. Use something like 
this:

void get_euler(dReal * matrix,dReal &kx,dReal &ky,dReal &kz)
{       
const dReal epsilon=0.0000001;

if(matrix[8] < 1-epsilon && matrix[8] > -1+epsilon){
        ky=-asin(matrix[8]);
        dReal c=cos(ky);
        kx= atan2(matrix[9]/c,matrix[10]/c);
        kz= atan2(matrix[4]/c,matrix[0]/c);
        }       
else    
        {       
        kz=0;   
        ky=-atan2(matrix[8],0);
        kx= atan2(-matrix[6],matrix[5]);
        }       
}       


-- 
:: Andrzej Szombierski :: qq at kuku.eu.org :: http://kuku.eu.org ::
:: anszom at bezkitu.com  :: radio bez kitu :: http://bezkitu.com ::



More information about the ODE mailing list