I'm interfacing with a video camera mounted on a plane. The camera can tell me its GPS position (latitude, longitude, altitude) and the GPS position of its view area's center point (called Line of Sight). I also know the camera's horizontal field of view and aspect ratio. I can also acquire the plane's heading, pitch and roll, and the heading and pitch angles of the camera. The library I'm using (like Google Earth in Java) can convert between GPS positions and Cartesian coordinates used by OpenGL and can also do a ray cast against Earth geometry and return the point of collision.
I want to find the four corners of the camera's viewing area as GPS positions so I can draw the camera's view on the globe. As I said, if I can get the Cartesian coords then I can do the conversion to GPS. Here's what I have so far.
- Convert camera position and line of sight to Cartesian coords.
- Calculate the camera's direction vector: losPosition - cameraPosition
- For each corner, rotate the direction vector by half the field of view in each direction
- Use the camera point and rotated direction vector as a ray; do a raycast into earth geometry
- Convert collision point back into GPS position
When I draw the resulting bounding box, it's in the right area on the globe, but the shape is totally wrong. My guess is that I need to rotate the rays around the plane's up/forward/right axes instead of the world axes. Am I on the right track? If so, is there an easy way to find those axes? Can you think of an easier, or even just different, approach to this problem?