I can't claim to be a quaternion expert, but it looks like you misunderstand
how they work - converting them to XYZ angles is not nearly as simple as you
seem to be suggesting.
Here's my own code to get euler angles from a matrix. Converting it to using
an osg Matrix will be trivial.

// The returned vector contains rotations about X,Y and Z axes
// Arguments returned in radians.
Vec3 Matrix4::GetEulerAngles() const
{
    Vec3 angles;

    //result of multiplying (0,1,0) by the matrix
    Vec3 yAxis(m_mat[1][0], m_mat[1][1], m_mat[1][2]);

    //find the rotation about the z-axis to rotate x onto the x-z plane
    const float adjacentZ = m_mat[0][0];
    const float oppositeZ = m_mat[0][1];
    const float hypotenuseZSqr = adjacentZ * adjacentZ + oppositeZ *
oppositeZ;
    const float hypotenuseZ = sqrtf(hypotenuseZSqr);

    angles.z = atan2(oppositeZ, adjacentZ);

    if (hypotenuseZ > 0.0f)
    {
        float yAxisY = (adjacentZ * yAxis.y - oppositeZ * yAxis.x) /
hypotenuseZ;
        yAxis.x = (adjacentZ * yAxis.x + oppositeZ * yAxis.y) / hypotenuseZ;
        yAxis.y = yAxisY;
    }

    //find the rotation about the y-axis to rotate x onto the x-axis

    const float oppositeY = m_mat[0][2];
    const float hypotenuseY = sqrtf(hypotenuseZSqr + oppositeY * oppositeY);

    angles.y = -atan2(oppositeY, hypotenuseZ);

    if (hypotenuseY > 0.0f)
    {
        yAxis.z = (hypotenuseZ * yAxis.z - yAxis.x * oppositeY) /
hypotenuseY;
    }

    //find the rotation about the x-axis to rotate y onto the x-y plane
    angles.x = atan2(yAxis.z, yAxis.y);

    return angles;
}
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to