I am trying to write an augmented reality application. I am using the compass, gyroscope, and GPS coordinates to create overlays. Everything is working great, except for when the user leaves portrait mode. Should just be a simple trig problem that I can't figure out.
To determine if a coordinate is in the field of view, I use an azimuth and inclination value of the center point of the iPhone that is calculated at the start of the program. Azimuth is defined as left and right movement when the phone is facing up, and inclination is up and down movement when the phone is facing up. I then update this value with gyroscope and compass data as it updates. So if I update the inclination and azimuth of the center point correctly, everything should work.
The problem is that when the iPhone is rotated, its definition of azimuth and inclination stay the same, with respect to the phone. So inclination is still defined as up to the top of the phone, even though the phone is sideways.
What I tried was doing something like this:
self.centerPoint.azimuth = (degToRad(angleX)*cosZ) + (degToRad(angleY)*sinZ);
self.centerPoint.inclination = (degToRad(angleY)*cosZ) + (degToRad(angleX)*sinZ);
where degToRad(x) converts from degrees to radians, cosZ and sinZ are the cos and sin of the z-angle from the gyroscope respectively, and angleX and angleY are the x and y angles from the gyroscope. The X-angle from the gyroscope measures up-down angle, Y-angle measures left-right, and Z-angle measures rotation of the phone from portrait to landscape.
Doesn't seem to be working. When I rotate the phone to the side, the inclination shoots up dramatically. Any trig people out there who can help?
I should add that normally, when only considering portrait orientation, I used: azimuth = degToRad(angleX) and inclination = degToRad(angleY). This works for portrait orientation. I should just have to multiply this by some factor to account for the different angle.