There are several ways to attack this problem. Working directly with heading, 
pitch, roll is problematic because of singularities. For me, I chose to use 
vector math to solve the problem.

The vector math for bearing calculation on a spheroid can be had as follows:

Let “N” be defined as (0,0,R) where “R” is the polar radius of the earth

Let “E” be defined as the camera position in geocentric Cartesian coordinates.

The unit vector “b” used in the formulas below is embedded in the third column 
of the camera view matrix so that bx = -view(0,2), by = -view(1,2), bz = 
-view(2,2)

Let “u” be defined as the “world up” unit vector at the camera position

“.” is the vector dot product and “^” is the vector cross product. Lower case 
represents unit vectors

proj_d = b – u . (b . u)
n = N – E
proj_n = n – u . (n . u)
proj_e = proj_n ^ u
bearing = atan2(proj_e . proj_d, proj_n . proj_d)

bearing is > 0 going CW to PI and < 0 going CCW to –PI. A bearing of 0.0 is 
true north.

For the compass, you can create a rotation matrix around the z-axis (i.e. 
rotation.makeRotate(bearing,(0,0,1)). Do this update on a callback for the 
compass node.

Hope this helps…

-Shayne

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49139#49139





_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to