determining angle of camera android
===

I have an interesting problem.  I am trying to trace out the angle of a users phone regardless of whether they are holding it in landscape or portrait or any where in between..

I am currently using SENSOR_ORIENTATION and getting YAW, ROLL, and Pitch.  I was also trying to get the angle of the users view port on the zaxis using yaw, and to correct for the users roll (landscape, portrait, or in between) i did some simple math..:

    double roll = phoneOri.getRoll();
    double yaw = phoneOri.getYaw()+roll;
            	
         if (yaw>=360){
            		yaw = (yaw - 360);
            	}
            	if (yaw<0){
            		yaw = (yaw+360);	
            	}

this code corrects the yaw and gives me the proper angle no matter what the roll position is..  
but this sort of math doesn't correct for pitch it seems.  if i hold my phone perpendicular to the floor i want to always get a pitch of 0 regardless of roll or yaw, if i face the back of the phone straight up to the sky and parallel to the ground i want to get 90, back to the ground -90;

here is how i am getting pitch roll and yaw:

    double yaw;
    double pitch;
    double roll;

    public void onSensorChanged(SensorEvent evt) {
                int type=evt.sensor.getType();
                if(type == Sensor.TYPE_ORIENTATION){
                	yaw = evt.values[0];
                	pitch = evt.values[1];
                	roll = evt.values[2];
                }



currently i get the following results:

![][1]


pitch = **-90** roll = **0**;

![enter image description here][2]


pitch = **0** roll = **90**;

![enter image description here][3]

pitch = **90** roll = **-20**;

![enter image description here][4]

pitch = **0** roll = **-90**;


  [1]: http://i.stack.imgur.com/mUecT.jpg
  [2]: http://i.stack.imgur.com/b9Tys.jpg
  [3]: http://i.stack.imgur.com/n4qTw.jpg
  [4]: http://i.stack.imgur.com/4CXfX.jpg

I am trying to get a pitch of 0 in any of these positions and then get a pitch between -90 and 90 respectively as the user tilts the phone on the HORIZON axis?

any ideas? oh and i should add that my application is locked to landscape mode..
