Inverting rotation matrix swaps pitch and roll

view story

http://stackoverflow.com – I've got rotation matrix from TYPE_ROTATION_VECTOR vector values. and tried to use it to rotate an object in my app. Worked fine. But what I really want is to rotate an object opposite to the direction of device's movement. Say, device is rotated around x axes for 30 degrees, I need my object to rotate around x axes to -30 degrees. It has to have an effect as if the object is staying where it is irrespective of devices movement. To do that I inverted(transposed) the rotation vector. Now rotation around x and y axis are completely incorrect, it looks like they are swapped. when i rotate device (HowTos)