-
-// These are wrapper functions around ssgSetNearFar() and ssgSetFOV()
-// which will post process and rewrite the resulting frustum if we
-// want to do asymmetric view frustums.
-
-static void fgHackFrustum() {
-
- // specify a percent of the configured view frustum to actually
- // display. This is a bit of a hack to achieve asymmetric view
- // frustums. For instance, if you want to display two monitors
- // side by side, you could specify each with a double fov, a 0.5
- // aspect ratio multiplier, and then the left side monitor would
- // have a left_pct = 0.0, a right_pct = 0.5, a bottom_pct = 0.0,
- // and a top_pct = 1.0. The right side monitor would have a
- // left_pct = 0.5 and a right_pct = 1.0.
-
- static SGPropertyNode *left_pct
- = fgGetNode("/sim/current-view/frustum-left-pct");
- static SGPropertyNode *right_pct
- = fgGetNode("/sim/current-view/frustum-right-pct");
- static SGPropertyNode *bottom_pct
- = fgGetNode("/sim/current-view/frustum-bottom-pct");
- static SGPropertyNode *top_pct
- = fgGetNode("/sim/current-view/frustum-top-pct");
-
- double left, right;
- double bottom, top;
- double zNear, zFar;
- sceneView->getProjectionMatrixAsFrustum(left, right, bottom, top, zNear, zFar);
- // cout << " l = " << f->getLeft()
- // << " r = " << f->getRight()
- // << " b = " << f->getBot()
- // << " t = " << f->getTop()
- // << " n = " << f->getNear()
- // << " f = " << f->getFar()
- // << endl;
-
- double width = right - left;
- double height = top - bottom;
-
- double l, r, t, b;
-
- if ( left_pct != NULL ) {
- l = left + width * left_pct->getDoubleValue();
- } else {
- l = left;
- }
-
- if ( right_pct != NULL ) {
- r = left + width * right_pct->getDoubleValue();
- } else {
- r = right;
- }
-
- if ( bottom_pct != NULL ) {
- b = bottom + height * bottom_pct->getDoubleValue();
- } else {
- b = bottom;
- }
-
- if ( top_pct != NULL ) {
- t = bottom + height * top_pct->getDoubleValue();
- } else {
- t = top;
+void FGRenderer::setCameraParameters(float vfov, float aspectRatio,
+ float zNear, float zFar)
+{
+ zNear = .1;
+ osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
+ viewer->getCamera()->setProjectionMatrixAsPerspective(vfov,
+ 1.0f / aspectRatio,
+ zNear, zFar);
+
+}
+bool
+FGRenderer::pick(std::vector<SGSceneryPick>& pickList,
+ const osgGA::GUIEventAdapter* ea)
+{
+ osgViewer::Viewer* viewer = globals->get_renderer()->getViewer();
+ // wipe out the return ...
+ pickList.clear();
+ typedef osgUtil::LineSegmentIntersector::Intersections Intersections;
+ Intersections intersections;
+
+ if (!computeIntersections(CameraGroup::getDefault(), ea, intersections))
+ return false;
+ for (Intersections::iterator hit = intersections.begin(),
+ e = intersections.end();
+ hit != e;
+ ++hit) {
+ const osg::NodePath& np = hit->nodePath;
+ osg::NodePath::const_reverse_iterator npi;
+ for (npi = np.rbegin(); npi != np.rend(); ++npi) {
+ SGSceneUserData* ud = SGSceneUserData::getSceneUserData(*npi);
+ if (!ud)
+ continue;
+ for (unsigned i = 0; i < ud->getNumPickCallbacks(); ++i) {
+ SGPickCallback* pickCallback = ud->getPickCallback(i);
+ if (!pickCallback)
+ continue;
+ SGSceneryPick sceneryPick;
+ sceneryPick.info.local = SGVec3d(hit->getLocalIntersectPoint());
+ sceneryPick.info.wgs84 = SGVec3d(hit->getWorldIntersectPoint());
+ sceneryPick.callback = pickCallback;
+ pickList.push_back(sceneryPick);
+ }
+ }