Roland Melkert Wrote:Also does anyone know the best/easiest way to extract the angles from an existing rotation matrix?I think I solved this, but if anyone knows a better method...
Code:
void TLDStepMetaLine::getRotStepAngles(const TGLMatrixd &matrix, double &x, double &y, double &z, const int roundTo) {
x=atan2(matrix.array2D[2][1], matrix.array2D[2][2]);
const double c2=sqrt(SQR(matrix.array2D[0][0])+SQR(matrix.array2D[1][0]));
y=atan2(-matrix.array2D[2][0], c2);
const double s1=sin(x);
const double c1=cos(x);
z=atan2(s1*matrix.array2D[0][2]-c1*matrix.array2D[0][1], c1*matrix.array2D[1][1]-s1*matrix.array2D[1][2]);
//allemaal neg nav de sign flips in de ROTSTEP spec.
x=-rad2Deg(x);
y=-rad2Deg(y);
z=-rad2Deg(z);
if (roundTo>0)
{
x=((int)round(x/roundTo))*roundTo;
y=((int)round(y/roundTo))*roundTo;
z=((int)round(z/roundTo))*roundTo;
}
};