How do I get orientation of body? I noticed the body_xmat, but it's a 3x3 matrix. How do I interpret this matrix, and how would I transform it to the 3DOF orientation?
This is an orthonormal matrix encoding the body orientation. In particular, if v is a vector in local body coordinates, then M*v is the same vector expressed in global coordinates (where M is the 3x3 matrix in question). If you prefer to express 3D orientations in some other format, it is up to you to implement the transformation. Note that MuJoCo also computes xquat which is the body orientation expressed as a unit quaternion.