- Timestamp:
- Mar 26, 2014 3:25:30 AM (10 years ago)
- Location:
- trunk/packages/vizservers/geovis
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/packages/vizservers/geovis/Renderer.cpp
r4247 r4273 23 23 #include <osgEarth/Bounds> 24 24 #include <osgEarth/Profile> 25 #include <osgEarth/Viewpoint> 25 26 #include <osgEarth/TerrainLayer> 26 27 #include <osgEarth/ImageLayer> … … 82 83 _manipulator = new osgEarth::Util::EarthManipulator; 83 84 _viewer->setCameraManipulator(_manipulator.get()); 84 _viewer->addEventHandler(new osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet())); 85 _stateManip = new osgGA::StateSetManipulator(_viewer->getCamera()->getOrCreateStateSet()); 86 _viewer->addEventHandler(_stateManip); 85 87 _coordsCallback = new MouseCoordsCallback(); 86 88 _mouseCoordsTool = new osgEarth::Util::MouseCoordsTool(mapNode); … … 293 295 mpOpt.color() = osg::Vec4(1, 1, 1, 1); 294 296 //mpOpt.minLOD() = 1; 297 // Sets shader uniform for terrain renderer (config var defaults to false) 298 mpOpt.enableLighting() = false; 295 299 osgEarth::MapNodeOptions mapNodeOpts(mpOpt); 296 mapNodeOpts.enableLighting() = false; 300 // Sets GL_LIGHTING state in MapNode's StateSet (config var defaults to true) 301 mapNodeOpts.enableLighting() = true; 297 302 osgEarth::MapNode *mapNode = new osgEarth::MapNode(map, mapNodeOpts); 298 303 _mapNode = mapNode; … … 328 333 } 329 334 _needsRedraw = true; 335 } 336 337 void Renderer::setLighting(bool state) 338 { 339 if (_mapNode.valid()) { 340 TRACE("Setting lighting: %d", state ? 1 : 0); 341 _mapNode->getOrCreateStateSet() 342 ->setMode(GL_LIGHTING, state ? 1 : 0); 343 } 344 _needsRedraw = true; 345 } 346 347 void Renderer::setTerrainVerticalScale(double scale) 348 { 349 if (_mapNode.valid()) { 350 _mapNode->getTerrainEngine()->setVerticalScale(scale); 351 } 352 _needsRedraw = true; 353 } 354 355 void Renderer::setTerrainLighting(bool state) 356 { 357 #if 1 358 if (_mapNode.valid()) { 359 // XXX: HACK alert 360 // Find the terrain engine container (might be above one or more decorators) 361 osg::Group *group = _mapNode->getTerrainEngine(); 362 while (group->getParent(0) != NULL && group->getParent(0) != _mapNode.get()) { 363 group = group->getParent(0); 364 } 365 if (group != NULL && group->getParent(0) == _mapNode.get()) { 366 TRACE("Setting terrain lighting: %d", state ? 1 : 0); 367 if (group->getOrCreateStateSet()->getUniform("oe_mode_GL_LIGHTING") != NULL) { 368 group->getStateSet()->getUniform("oe_mode_GL_LIGHTING")->set(state); 369 } else { 370 ERROR("Can't get terrain lighting uniform"); 371 } 372 } else { 373 ERROR("Can't get terrain lighting uniform"); 374 } 375 } 376 #else 377 if (_stateManip.valid()) { 378 _stateManip->setLightingEnabled(state); 379 } 380 #endif 381 _needsRedraw = true; 382 } 383 384 void Renderer::setTerrainWireframe(bool state) 385 { 386 #if 0 387 if (_mapNode.valid()) { 388 TRACE("Setting terrain wireframe: %d", state ? 1 : 0); 389 osg::StateSet *state = _mapNode->getOrCreateStateSet(); 390 osg::PolygonMode *pmode = dynamic_cast< osg::PolygonMode* >(state->getAttribute(osg::StateAttribute::POLYGONMODE)); 391 if (pmode == NULL) { 392 pmode = new osg::PolygonMode; 393 state->setAttribute(pmode); 394 } 395 if (state) { 396 pmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::LINE); 397 } else { 398 pmode->setMode(osg::PolygonMode::FRONT_AND_BACK, osg::PolygonMode::FILL); 399 } 400 } 401 #else 402 if (_stateManip.valid()) { 403 _stateManip->setPolygonMode(state ? osg::PolygonMode::LINE : osg::PolygonMode::FILL); 404 } 405 #endif 406 _needsRedraw = true; 407 } 408 409 void Renderer::setViewpoint(const osgEarth::Viewpoint& v, double durationSecs) 410 { 411 if (_manipulator.valid()) { 412 _manipulator->setViewpoint(v, durationSecs); 413 } 414 _needsRedraw = true; 415 } 416 417 osgEarth::Viewpoint Renderer::getViewpoint() 418 { 419 if (_manipulator.valid()) { 420 return _manipulator->getViewpoint(); 421 } else { 422 // Uninitialized, invalid viewpoint 423 return osgEarth::Viewpoint(); 424 } 330 425 } 331 426 … … 602 697 x, y, (absolute ? 1 : 0)); 603 698 699 // Wants mouse delta x,y in normalized screen coords 604 700 _manipulator->pan(x, y); 605 701 _needsRedraw = true; … … 628 724 // FIXME: zoom here wants y mouse coords in normalized viewport coords 629 725 630 _manipulator->zoom(0, z); 726 //_manipulator->zoom(0, z); 727 728 double dist = _manipulator->getDistance(); 729 dist *= (1.0 + z); 730 _manipulator->setDistance(dist); 731 631 732 _needsRedraw = true; 632 733 } -
trunk/packages/vizservers/geovis/Renderer.h
r4246 r4273 19 19 #include <osg/TransferFunction> 20 20 #include <osgViewer/Viewer> 21 #include <osgGA/StateSetManipulator> 21 22 22 23 #include <osgEarth/Map> 24 #include <osgEarth/Viewpoint> 23 25 #include <osgEarth/ImageLayer> 24 26 #include <osgEarth/ElevationLayer> … … 154 156 void setLighting(bool state); 155 157 158 void setTerrainLighting(bool state); 159 160 void setTerrainVerticalScale(double scale); 161 162 void setTerrainWireframe(bool state); 163 156 164 // Image raster layers 157 165 … … 221 229 return _windowHeight; 222 230 } 231 232 // Camera 233 234 osgEarth::Viewpoint getViewpoint(); 235 236 void setViewpoint(const osgEarth::Viewpoint& v, double durationSecs = 0.0); 223 237 224 238 void resetCamera(bool resetOrientation = true); … … 304 318 osg::ref_ptr<MouseCoordsCallback> _coordsCallback; 305 319 osg::ref_ptr<osgEarth::Util::EarthManipulator> _manipulator; 320 osg::ref_ptr<osgGA::StateSetManipulator> _stateManip; 306 321 }; 307 322 -
trunk/packages/vizservers/geovis/RendererCmd.cpp
r4246 r4273 887 887 } 888 888 889 static int 890 MapTerrainEdgesOp(ClientData clientData, Tcl_Interp *interp, int objc, 891 Tcl_Obj *const *objv) 892 { 893 bool state; 894 if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) { 895 return TCL_ERROR; 896 } 897 TRACE("Not implemented"); 898 //g_renderer->setTerrainEdges(state); 899 return TCL_OK; 900 } 901 902 static int 903 MapTerrainLightingOp(ClientData clientData, Tcl_Interp *interp, int objc, 904 Tcl_Obj *const *objv) 905 { 906 bool state; 907 if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) { 908 return TCL_ERROR; 909 } 910 911 g_renderer->setTerrainLighting(state); 912 return TCL_OK; 913 } 914 915 static int 916 MapTerrainLineColorOp(ClientData clientData, Tcl_Interp *interp, int objc, 917 Tcl_Obj *const *objv) 918 { 919 float color[3]; 920 if (GetFloatFromObj(interp, objv[2], &color[0]) != TCL_OK || 921 GetFloatFromObj(interp, objv[3], &color[1]) != TCL_OK || 922 GetFloatFromObj(interp, objv[4], &color[2]) != TCL_OK) { 923 return TCL_ERROR; 924 } 925 TRACE("Not implemented"); 926 //g_renderer->setTerrainLineColor(color); 927 return TCL_OK; 928 } 929 930 static int 931 MapTerrainVertScaleOp(ClientData clientData, Tcl_Interp *interp, int objc, 932 Tcl_Obj *const *objv) 933 { 934 double scale; 935 if (Tcl_GetDoubleFromObj(interp, objv[3], &scale) != TCL_OK) { 936 return TCL_ERROR; 937 } 938 939 g_renderer->setTerrainVerticalScale(scale); 940 return TCL_OK; 941 } 942 943 static int 944 MapTerrainWireframeOp(ClientData clientData, Tcl_Interp *interp, int objc, 945 Tcl_Obj *const *objv) 946 { 947 bool state; 948 if (GetBooleanFromObj(interp, objv[3], &state) != TCL_OK) { 949 return TCL_ERROR; 950 } 951 952 g_renderer->setTerrainWireframe(state); 953 return TCL_OK; 954 } 955 956 static CmdSpec mapTerrainOps[] = { 957 {"edges", 1, MapTerrainEdgesOp, 4, 4, "bool"}, 958 {"lighting", 2, MapTerrainLightingOp, 4, 4, "bool"}, 959 {"linecolor", 2, MapTerrainLineColorOp, 6, 6, "r g b"}, 960 {"vertscale", 1, MapTerrainVertScaleOp, 4, 4, "val"}, 961 {"wireframe", 1, MapTerrainWireframeOp, 4, 4, "bool"}, 962 }; 963 static int nMapTerrainOps = NumCmdSpecs(mapTerrainOps); 964 965 static int 966 MapTerrainOp(ClientData clientData, Tcl_Interp *interp, int objc, 967 Tcl_Obj *const *objv) 968 { 969 Tcl_ObjCmdProc *proc; 970 971 proc = GetOpFromObj(interp, nMapTerrainOps, mapTerrainOps, 972 CMDSPEC_ARG2, objc, objv, 0); 973 if (proc == NULL) { 974 return TCL_ERROR; 975 } 976 return (*proc) (clientData, interp, objc, objv); 977 } 978 889 979 static CmdSpec mapOps[] = { 890 {"layer", 2, MapLayerOp, 3, 9, "op ?params...?"},980 {"layer", 2, MapLayerOp, 3, 0, "op ?params...?"}, 891 981 {"load", 2, MapLoadOp, 4, 5, "options"}, 892 982 {"reset", 1, MapResetOp, 3, 8, "type ?profile xmin ymin xmax ymax?"}, 983 {"terrain", 1, MapTerrainOp, 3, 0, "op ?params...?"}, 893 984 }; 894 985 static int nMapOps = NumCmdSpecs(mapOps);
Note: See TracChangeset
for help on using the changeset viewer.