+typedef osg::ref_ptr<osg::Node> NodeRef;
+typedef nasal::Ghost<NodeRef> NasalNode;
+
+/**
+ * Get position (lat, lon, elevation) and orientation (heading, pitch, roll) of
+ * model.
+ */
+static naRef f_node_getPose( const osg::Node& node,
+ const nasal::CallContext& ctx )
+{
+ osg::NodePathList parent_paths = node.getParentalNodePaths();
+ for( osg::NodePathList::const_iterator path = parent_paths.begin();
+ path != parent_paths.end();
+ ++path )
+ {
+ osg::Matrix local_to_world = osg::computeLocalToWorld(*path);
+ if( !local_to_world.valid() )
+ continue;
+
+ SGGeod coord = SGGeod::fromCart( toSG(local_to_world.getTrans()) );
+ if( !coord.isValid() )
+ continue;
+
+ osg::Matrix local_frame = makeZUpFrameRelative(coord),
+ inv_local;
+ inv_local.invert_4x3(local_frame);
+ local_to_world.postMult(inv_local);
+
+ SGQuatd rotate = toSG(local_to_world.getRotate());
+ double hdg, pitch, roll;
+ rotate.getEulerDeg(hdg, pitch, roll);
+
+ nasal::Hash pose(ctx.to_nasal(coord), ctx.c);
+ pose.set("heading", hdg);
+ pose.set("pitch", pitch);
+ pose.set("roll", roll);
+ return pose.get_naRef();
+ }
+
+ return naNil();
+}
+