Changeset 10999 for OpenSceneGraph/trunk/src/osgViewer/View.cpp
- Timestamp:
- 01/26/10 15:57:44 (3 years ago)
- Files:
-
- 1 modified
-
OpenSceneGraph/trunk/src/osgViewer/View.cpp (modified) (94 diffs)
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/src/osgViewer/View.cpp
r10764 r10999 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield 2 2 * 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 3 * This library is open source and may be redistributed and/or modified under 4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or 5 5 * (at your option) any later version. The full license is in LICENSE file 6 6 * included with this distribution, and on the openscenegraph.org website. 7 * 7 * 8 8 * This library is distributed in the hope that it will be useful, 9 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 11 * OpenSceneGraph Public License for more details. 12 12 */ … … 37 37 CollectedCoordinateSystemNodesVisitor(): 38 38 NodeVisitor(osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN) {} 39 39 40 40 META_NodeVisitor("osgViewer","CollectedCoordinateSystemNodesVisitor") 41 41 … … 60 60 traverse(node); 61 61 } 62 62 63 63 osg::NodePath _pathToCoordinateSystemNode; 64 64 }; … … 72 72 ViewerCoordinateFrameCallback(osgViewer::View* view): 73 73 _view(view) {} 74 74 75 75 virtual osg::CoordinateFrame getCoordinateFrame(const osg::Vec3d& position) const 76 76 { … … 78 78 79 79 osg::NodePath tmpPath = _view->getCoordinateSystemNodePath(); 80 80 81 81 if (!tmpPath.empty()) 82 { 82 { 83 83 osg::Matrixd coordinateFrame; 84 84 … … 87 87 { 88 88 osg::Vec3 local_position = position*osg::computeWorldToLocal(tmpPath); 89 89 90 90 // get the coordinate frame in world coords. 91 91 coordinateFrame = csn->computeLocalCoordinateFrame(local_position)* osg::computeLocalToWorld(tmpPath); … … 122 122 } 123 123 } 124 124 125 125 protected: 126 126 virtual ~ViewerCoordinateFrameCallback() {} 127 127 128 128 osg::observer_ptr<osgViewer::View> _view; 129 129 }; … … 147 147 // make sure View is safe to reference multi-threaded. 148 148 setThreadSafeRefUnref(true); 149 149 150 150 // need to attach a Renderer to the master camera which has been default constructed 151 151 getCamera()->setRenderer(createRenderer(getCamera())); 152 152 153 153 setEventQueue(new osgGA::EventQueue); 154 154 155 155 setStats(new osg::Stats("View")); 156 156 } … … 183 183 184 184 #if 1 185 osgViewer::View* rhs_osgViewer = dynamic_cast<osgViewer::View*>(&rhs); 185 osgViewer::View* rhs_osgViewer = dynamic_cast<osgViewer::View*>(&rhs); 186 186 if (rhs_osgViewer) 187 187 { 188 188 189 189 // copy across rhs 190 190 _startTick = rhs_osgViewer->_startTick; … … 195 195 _scene = rhs_osgViewer->_scene; 196 196 } 197 197 198 198 if (rhs_osgViewer->_cameraManipulator.valid()) 199 199 { 200 200 _cameraManipulator = rhs_osgViewer->_cameraManipulator; 201 201 } 202 202 203 203 _eventHandlers.insert(_eventHandlers.end(), rhs_osgViewer->_eventHandlers.begin(), rhs_osgViewer->_eventHandlers.end()); 204 204 … … 208 208 _fusionDistanceMode = rhs_osgViewer->_fusionDistanceMode; 209 209 _fusionDistanceValue = rhs_osgViewer->_fusionDistanceValue; 210 211 210 211 212 212 // clear rhs 213 213 rhs_osgViewer->_frameStamp = 0; … … 215 215 rhs_osgViewer->_cameraManipulator = 0; 216 216 rhs_osgViewer->_eventHandlers.clear(); 217 217 218 218 rhs_osgViewer->_coordinateSystemNodePath.clear(); 219 219 220 220 rhs_osgViewer->_displaySettings = 0; 221 221 } … … 236 236 { 237 237 osg::notify(osg::INFO)<<"View::init()"<<std::endl; 238 238 239 239 osg::ref_ptr<osgGA::GUIEventAdapter> initEvent = _eventQueue->createEvent(); 240 240 initEvent->setEventType(osgGA::GUIEventAdapter::FRAME); 241 241 242 242 if (_cameraManipulator.valid()) 243 243 { … … 290 290 osgUtil::Optimizer::StaticObjectDetectionVisitor sodv; 291 291 getSceneData()->accept(sodv); 292 292 293 293 // make sure that existing scene graph objects are allocated with thread safe ref/unref 294 if (getViewerBase() && 295 getViewerBase()->getThreadingModel()!=ViewerBase::SingleThreaded) 294 if (getViewerBase() && 295 getViewerBase()->getThreadingModel()!=ViewerBase::SingleThreaded) 296 296 { 297 297 getSceneData()->setThreadSafeRefUnref(true); 298 298 } 299 299 300 300 // update the scene graph so that it has enough GL object buffer memory for the graphics contexts that will be using it. 301 301 getSceneData()->resizeGLObjectBuffers(osg::DisplaySettings::instance()->getMaxNumberOfGraphicsContexts()); 302 302 } 303 303 304 304 computeActiveCoordinateSystemNodePath(); 305 305 … … 342 342 { 343 343 _cameraManipulator = manipulator; 344 344 345 345 if (_cameraManipulator.valid()) 346 346 { … … 348 348 349 349 if (getSceneData()) _cameraManipulator->setNode(getSceneData()); 350 350 351 351 osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent(); 352 352 … … 407 407 // now search for CoordinateSystemNode's for which we want to track. 408 408 osg::Node* subgraph = getSceneData(); 409 409 410 410 if (subgraph) 411 411 { 412 412 413 413 CollectedCoordinateSystemNodesVisitor ccsnv; 414 414 subgraph->accept(ccsnv); … … 419 419 return; 420 420 } 421 } 421 } 422 422 423 423 // otherwise no node path found so reset to empty. … … 428 428 { 429 429 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 430 if (!wsi) 430 if (!wsi) 431 431 { 432 432 osg::notify(osg::NOTICE)<<"View::setUpViewAcrossAllScreens() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl; 433 433 return; 434 434 } 435 435 436 436 osg::DisplaySettings* ds = _displaySettings.valid() ? _displaySettings.get() : osg::DisplaySettings::instance(); 437 438 double fovy, aspectRatio, zNear, zFar; 437 438 double fovy, aspectRatio, zNear, zFar; 439 439 _camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); 440 440 441 441 osg::GraphicsContext::ScreenIdentifier si; 442 442 si.readDISPLAY(); 443 443 444 444 // displayNum has not been set so reset it to 0. 445 445 if (si.displayNum<0) si.displayNum = 0; 446 446 447 447 unsigned int numScreens = wsi->getNumScreens(si); 448 448 if (numScreens==1) 449 449 { 450 450 if (si.screenNum<0) si.screenNum = 0; 451 451 452 452 unsigned int width, height; 453 453 wsi->getScreenResolution(si, width, height); … … 468 468 469 469 _camera->setGraphicsContext(gc.get()); 470 470 471 471 osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(gc.get()); 472 472 if (gw) … … 508 508 translate_x += double(width) / (double(height) * aspectRatio); 509 509 } 510 510 511 511 bool stereoSlitScreens = numScreens==2 && 512 512 ds->getStereoMode()==osg::DisplaySettings::HORIZONTAL_SPLIT && 513 513 ds->getStereo(); 514 514 515 515 for(unsigned int i=0; i<numScreens; ++i) 516 516 { 517 517 si.screenNum = i; 518 518 519 519 unsigned int width, height; 520 520 wsi->getScreenResolution(si, width, height); … … 559 559 { 560 560 unsigned int leftCameraNum = (ds->getSplitStereoHorizontalEyeMapping()==osg::DisplaySettings::LEFT_EYE_LEFT_VIEWPORT) ? 0 : 1; 561 561 562 562 osg::ref_ptr<osg::DisplaySettings> ds_local = new osg::DisplaySettings(*ds); 563 563 ds_local->setStereoMode(leftCameraNum==i ? osg::DisplaySettings::LEFT_EYE : osg::DisplaySettings::RIGHT_EYE); 564 564 camera->setDisplaySettings(ds_local.get()); 565 565 566 566 addSlave(camera.get(), osg::Matrixd(), osg::Matrixd() ); 567 567 } … … 588 588 traits->readDISPLAY(); 589 589 if (traits->displayNum<0) traits->displayNum = 0; 590 590 591 591 traits->screenNum = screenNum; 592 592 traits->x = x; … … 613 613 } 614 614 615 double fovy, aspectRatio, zNear, zFar; 615 double fovy, aspectRatio, zNear, zFar; 616 616 _camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); 617 617 … … 634 634 { 635 635 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 636 if (!wsi) 636 if (!wsi) 637 637 { 638 638 osg::notify(osg::NOTICE)<<"View::setUpViewOnSingleScreen() : Error, no WindowSystemInterface available, cannot create windows."<<std::endl; … … 644 644 osg::GraphicsContext::ScreenIdentifier si; 645 645 si.readDISPLAY(); 646 646 647 647 // displayNum has not been set so reset it to 0. 648 648 if (si.displayNum<0) si.displayNum = 0; … … 680 680 } 681 681 682 double fovy, aspectRatio, zNear, zFar; 682 double fovy, aspectRatio, zNear, zFar; 683 683 _camera->getProjectionMatrixAsPerspective(fovy, aspectRatio, zNear, zFar); 684 684 … … 702 702 osg::Vec3d center(0.0,0.0,0.0); 703 703 osg::Vec3d eye(0.0,0.0,0.0); 704 704 705 705 double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); 706 706 707 707 bool centerProjection = false; 708 708 709 709 osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); 710 710 711 711 osg::notify(osg::INFO)<<"create3DSphericalDisplayDistortionMesh : Projector position = "<<projector<<std::endl; 712 712 osg::notify(osg::INFO)<<"create3DSphericalDisplayDistortionMesh : distance = "<<distance<<std::endl; … … 725 725 float height = heightVector.length(); 726 726 yAxis /= height; 727 727 728 728 int noSteps = 50; 729 729 … … 736 736 osg::Vec3 dx = xAxis*(width/((float)(noSteps-1))); 737 737 osg::Vec3 dy = yAxis*(height/((float)(noSteps-1))); 738 738 739 739 osg::Vec3d screenCenter = origin + widthVector*0.5f + heightVector*0.5f; 740 740 float screenRadius = heightVector.length() * 0.5f; … … 756 756 757 757 phi *= 2.0; 758 758 759 759 if (theta<0.0) theta += 2.0*osg::PI; 760 760 … … 770 770 osg::Vec2 texcoord1(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2); 771 771 if (intensityMap) 772 { 772 { 773 773 colors->push_back(intensityMap->getColor(texcoord1)); 774 774 } … … 798 798 799 799 // osg::notify(osg::NOTICE)<<"theta = "<<theta<< "phi="<<phi<<std::endl; 800 800 801 801 double f = distance * sin(phi); 802 802 double e = distance * cos(phi) + sqrt( sphere_radius*sphere_radius - f*f); … … 804 804 double h = e * sin(phi); 805 805 double z = l - distance; 806 806 807 807 osg::Vec3 texcoord(h * cos(theta) / sphere_radius, 808 808 h * sin(theta) / sphere_radius, … … 814 814 osg::Vec2 texcoord1(theta/(2.0*osg::PI), 1.0f - phi/osg::PI_2); 815 815 if (intensityMap) 816 { 816 { 817 817 colors->push_back(intensityMap->getColor(texcoord1)); 818 818 } … … 828 828 } 829 829 } 830 830 831 831 // pass the created vertex array to the points geometry object. 832 832 geometry->setVertexArray(vertices); … … 848 848 geometry->addPrimitiveSet(elements); 849 849 } 850 850 851 851 return geometry; 852 852 } … … 856 856 osg::notify(osg::INFO)<<"View::setUpViewFor3DSphericalDisplay(rad="<<radius<<", cllr="<<collar<<", sn="<<screenNum<<", im="<<intensityMap<<")"<<std::endl; 857 857 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 858 if (!wsi) 858 if (!wsi) 859 859 { 860 860 osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; … … 864 864 osg::GraphicsContext::ScreenIdentifier si; 865 865 si.readDISPLAY(); 866 866 867 867 // displayNum has not been set so reset it to 0. 868 868 if (si.displayNum<0) si.displayNum = 0; … … 885 885 traits->doubleBuffer = true; 886 886 traits->sharedContext = 0; 887 887 888 888 889 889 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); … … 893 893 return; 894 894 } 895 895 896 896 bool applyIntensityMapAsColours = true; 897 897 … … 911 911 texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); 912 912 texture->setWrap(osg::Texture::WRAP_R,osg::Texture::CLAMP_TO_EDGE); 913 914 #if 0 913 914 #if 0 915 915 osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; 916 916 GLenum buffer = GL_FRONT; … … 938 938 } 939 939 940 940 941 941 // top face 942 942 { … … 1034 1034 addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate(osg::inDegrees(180.0f), 1.0,0.0,0.0)); 1035 1035 } 1036 1036 1037 1037 getCamera()->setProjectionMatrixAsPerspective(90.0f, 1.0, 1, 1000.0); 1038 1038 … … 1042 1042 geode->addDrawable(create3DSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar, applyIntensityMapAsColours ? intensityMap : 0, projectorMatrix)); 1043 1043 1044 // new we need to add the texture to the mesh, we do so by creating a 1044 // new we need to add the texture to the mesh, we do so by creating a 1045 1045 // StateSet to contain the Texture StateAttribute. 1046 1046 osg::StateSet* stateset = geode->getOrCreateStateSet(); … … 1065 1065 camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); 1066 1066 //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); 1067 1067 1068 1068 camera->setProjectionMatrixAsOrtho2D(0,width,0,height); 1069 1069 camera->setViewMatrix(osg::Matrix::identity()); … … 1071 1071 // add subgraph to render 1072 1072 camera->addChild(geode); 1073 1073 1074 1074 camera->setName("DistortionCorrectionCamera"); 1075 1075 1076 1076 addSlave(camera.get(), osg::Matrixd(), osg::Matrixd(), false); 1077 1077 } 1078 1078 1079 1079 getCamera()->setNearFarRatio(0.0001f); 1080 1080 1081 1081 if (getLightingMode()==osg::View::HEADLIGHT) 1082 1082 { … … 1090 1090 osg::Vec3d center(0.0,0.0,0.0); 1091 1091 osg::Vec3d eye(0.0,0.0,0.0); 1092 1092 1093 1093 double distance = sqrt(sphere_radius*sphere_radius - collar_radius*collar_radius); 1094 1094 bool flip = false; … … 1096 1096 1097 1097 osg::Vec3d projector = eye - osg::Vec3d(0.0,0.0, distance); 1098 1099 1098 1099 1100 1100 osg::notify(osg::INFO)<<"createParoramicSphericalDisplayDistortionMesh : Projector position = "<<projector<<std::endl; 1101 1101 osg::notify(osg::INFO)<<"createParoramicSphericalDisplayDistortionMesh : distance = "<<distance<<std::endl; … … 1113 1113 float height = heightVector.length(); 1114 1114 yAxis /= height; 1115 1115 1116 1116 int noSteps = 160; 1117 1117 … … 1124 1124 osg::Vec3 dx = xAxis*(width/((float)(noSteps-2))); 1125 1125 osg::Vec3 dy = yAxis*(height/((float)(noSteps-1))); 1126 1126 1127 1127 osg::Vec3 top = origin + yAxis*height; 1128 1128 1129 1129 osg::Vec3 screenCenter = origin + widthVector*0.5f + heightVector*0.5f; 1130 1130 float screenRadius = heightVector.length() * 0.5f; 1131 1131 1132 1132 geometry->getOrCreateStateSet()->setMode(GL_CULL_FACE, osg::StateAttribute::OFF | osg::StateAttribute::PROTECTED); 1133 1133 … … 1140 1140 double theta = texcoord.x() * 2.0 * osg::PI; 1141 1141 double phi = (1.0-texcoord.y()) * osg::PI; 1142 1142 1143 1143 if (texcoord_flip) texcoord.y() = 1.0f - texcoord.y(); 1144 1144 1145 1145 osg::Vec3 pos(sin(phi)*sin(theta), sin(phi)*cos(theta), cos(phi)); 1146 1146 pos = pos*projectorMatrix; 1147 1147 1148 1148 double alpha = atan2(pos.x(), pos.y()); 1149 1149 if (alpha<0.0) alpha += 2.0*osg::PI; 1150 1150 1151 1151 double beta = atan2(sqrt(pos.x()*pos.x() + pos.y()*pos.y()), pos.z()); 1152 1152 if (beta<0.0) beta += 2.0*osg::PI; … … 1154 1154 double gamma = atan2(sqrt(double(pos.x()*pos.x() + pos.y()*pos.y())), double(pos.z()+distance)); 1155 1155 if (gamma<0.0) gamma += 2.0*osg::PI; 1156 1157 1156 1157 1158 1158 osg::Vec3 v = screenCenter + osg::Vec3(sin(alpha)*gamma*2.0/osg::PI, -cos(alpha)*gamma*2.0/osg::PI, 0.0f)*screenRadius; 1159 1159 1160 1160 if (flip) 1161 1161 vertices->push_back(osg::Vec3(v.x(), top.y()-(v.y()-origin.y()),v.z())); … … 1164 1164 1165 1165 texcoords0->push_back( texcoord ); 1166 1166 1167 1167 osg::Vec2 texcoord1(alpha/(2.0*osg::PI), 1.0f - beta/osg::PI); 1168 1168 if (intensityMap) … … 1201 1201 int i3 = j+1+(i)*noSteps; 1202 1202 int i4 = j+1+(i+1)*noSteps; 1203 1203 1204 1204 osg::Vec3& v1 = (*vertices)[i1]; 1205 1205 osg::Vec3& v2 = (*vertices)[i2]; … … 1211 1211 if ((v3-screenCenter).length()>screenRadius) continue; 1212 1212 if ((v4-screenCenter).length()>screenRadius) continue; 1213 1213 1214 1214 elements->push_back(i1); 1215 1215 elements->push_back(i2); 1216 1216 elements->push_back(i3); 1217 1217 1218 1218 elements->push_back(i1); 1219 1219 elements->push_back(i3); … … 1221 1221 } 1222 1222 } 1223 1223 1224 1224 return geometry; 1225 1225 } … … 1230 1230 1231 1231 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 1232 if (!wsi) 1232 if (!wsi) 1233 1233 { 1234 1234 osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; … … 1238 1238 osg::GraphicsContext::ScreenIdentifier si; 1239 1239 si.readDISPLAY(); 1240 1240 1241 1241 // displayNum has not been set so reset it to 0. 1242 1242 if (si.displayNum<0) si.displayNum = 0; … … 1258 1258 traits->doubleBuffer = true; 1259 1259 traits->sharedContext = 0; 1260 1260 1261 1261 1262 1262 bool applyIntensityMapAsColours = true; … … 1283 1283 texture->setWrap(osg::Texture::WRAP_S,osg::Texture::CLAMP_TO_EDGE); 1284 1284 texture->setWrap(osg::Texture::WRAP_T,osg::Texture::CLAMP_TO_EDGE); 1285 1286 #if 0 1285 1286 #if 0 1287 1287 osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; 1288 1288 GLenum buffer = GL_FRONT; … … 1315 1315 geode->addDrawable(createParoramicSphericalDisplayDistortionMesh(osg::Vec3(0.0f,0.0f,0.0f), osg::Vec3(width,0.0f,0.0f), osg::Vec3(0.0f,height,0.0f), radius, collar, applyIntensityMapAsColours ? intensityMap : 0, projectorMatrix)); 1316 1316 1317 // new we need to add the texture to the mesh, we do so by creating a 1317 // new we need to add the texture to the mesh, we do so by creating a 1318 1318 // StateSet to contain the Texture StateAttribute. 1319 1319 osg::StateSet* stateset = geode->getOrCreateStateSet(); … … 1342 1342 camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); 1343 1343 //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); 1344 1344 1345 1345 camera->setProjectionMatrixAsOrtho2D(0,width,0,height); 1346 1346 camera->setViewMatrix(osg::Matrix::identity()); … … 1348 1348 // add subgraph to render 1349 1349 camera->addChild(geode); 1350 1350 1351 1351 camera->setName("DistortionCorrectionCamera"); 1352 1352 … … 1360 1360 1361 1361 osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface(); 1362 if (!wsi) 1362 if (!wsi) 1363 1363 { 1364 1364 osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl; … … 1368 1368 osg::GraphicsContext::ScreenIdentifier si; 1369 1369 si.readDISPLAY(); 1370 1370 1371 1371 // displayNum has not been set so reset it to 0. 1372 1372 if (si.displayNum<0) si.displayNum = 0; 1373 1373 1374 1374 si.screenNum = screenNum; 1375 1375 … … 1388 1388 traits->doubleBuffer = true; 1389 1389 traits->sharedContext = 0; 1390 1390 1391 1391 1392 1392 osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get()); … … 1415 1415 textureD->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR); 1416 1416 1417 #if 0 1417 #if 0 1418 1418 osg::Camera::RenderTargetImplementation renderTargetImplementation = osg::Camera::SEPERATE_WINDOW; 1419 1419 GLenum buffer = GL_FRONT; … … 1482 1482 for (int x=0; x<=9; ++x){ 1483 1483 for (int y=7; y>=0; --y){ 1484 int i = 2*(7-y)+16*x; 1484 int i = 2*(7-y)+16*x; 1485 1485 cheader[i] = (((1<<(y))&(header[x])) << (7-(y))); 1486 1486 } 1487 1487 } 1488 } 1488 } 1489 1489 textureHeader->setImage(imageheader.get()); 1490 1490 } … … 1531 1531 stateset->addUniform(new osg::Uniform("wow_tcolor", 1)); 1532 1532 stateset->addUniform(new osg::Uniform("wow_tdepth", 2)); 1533 1533 1534 1534 osg::Shader *frag = new osg::Shader(osg::Shader::FRAGMENT); 1535 1535 frag->setShaderSource(" "\ … … 1589 1589 camera->setInheritanceMask(camera->getInheritanceMask() & ~osg::CullSettings::CLEAR_COLOR & ~osg::CullSettings::COMPUTE_NEAR_FAR_MODE); 1590 1590 //camera->setComputeNearFarMode(osg::CullSettings::DO_NOT_COMPUTE_NEAR_FAR); 1591 1591 1592 1592 camera->setProjectionMatrixAsOrtho2D(0,width,0,height); 1593 1593 camera->setViewMatrix(osg::Matrix::identity()); … … 1595 1595 // add subgraph to render 1596 1596 camera->addChild(geode); 1597 1597 1598 1598 camera->setName("WoWCamera"); 1599 1599 … … 1610 1610 1611 1611 osg::Node* sceneData = _scene.valid() ? _scene->getSceneData() : 0; 1612 1612 1613 1613 if (_cameraManipulator.valid()) 1614 1614 { 1615 1615 _cameraManipulator->setNode(sceneData); 1616 1616 1617 1617 osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent(); 1618 1618 … … 1624 1624 _camera->removeChildren(0,_camera->getNumChildren()); 1625 1625 if (sceneData) _camera->addChild(sceneData); 1626 1626 1627 1627 Renderer* renderer = dynamic_cast<Renderer*>(_camera->getRenderer()); 1628 1628 if (renderer) renderer->setCompileOnNextDraw(true); … … 1637 1637 slave._camera->removeChildren(0,slave._camera->getNumChildren()); 1638 1638 if (sceneData) slave._camera->addChild(sceneData); 1639 1639 1640 1640 Renderer* renderer = dynamic_cast<Renderer*>(slave._camera->getRenderer()); 1641 1641 if (renderer) renderer->setCompileOnNextDraw(true); 1642 1642 } 1643 } 1643 } 1644 1644 } 1645 1645 … … 1671 1671 { 1672 1672 osg::notify(osg::INFO)<<"View::requestWarpPointer("<<x<<","<<y<<")"<<std::endl; 1673 1673 1674 1674 float local_x, local_y; 1675 1675 const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); … … 1697 1697 { 1698 1698 if (_camera == camera) return true; 1699 1699 1700 1700 for(unsigned i=0; i<getNumSlaves(); ++i) 1701 1701 { … … 1708 1708 const osg::Camera* View::getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const 1709 1709 { 1710 const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); 1710 const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState(); 1711 1711 const osgViewer::GraphicsWindow* gw = dynamic_cast<const osgViewer::GraphicsWindow*>(eventState->getGraphicsContext()); 1712 1712 … … 1720 1720 { 1721 1721 const osg::Viewport* viewport = _camera->getViewport(); 1722 1722 1723 1723 double new_x = x; 1724 1724 double new_y = y; … … 1731 1731 static_cast<double>(_camera->getGraphicsContext()->getTraits()->height) * (y - eventState->getYmin())/(eventState->getYmax()-eventState->getXmin()); 1732 1732 } 1733 1734 if (viewport && 1733 1734 if (viewport && 1735 1735 new_x >= (viewport->x()-epsilon) && new_y >= (viewport->y()-epsilon) && 1736 1736 new_x < (viewport->x()+viewport->width()-1.0+epsilon) && new_y <= (viewport->y()+viewport->height()-1.0+epsilon) ) … … 1746 1746 1747 1747 osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix(); 1748 1748 1749 1749 // convert to non dimensional 1750 1750 x = (x - eventState->getXmin()) * 2.0 / (eventState->getXmax()-eventState->getXmin()) - 1.0; … … 1752 1752 1753 1753 if (view_invert_y) y = - y; 1754 1754 1755 1755 for(int i=getNumSlaves()-1; i>=0; --i) 1756 1756 { 1757 1757 const Slave& slave = getSlave(i); 1758 if (slave._camera.valid() && 1758 if (slave._camera.valid() && 1759 1759 slave._camera->getAllowEventFocus() && 1760 1760 slave._camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER) … … 1776 1776 //osg::notify(osg::NOTICE)<<" new_coord "<<new_coord<<std::endl;; 1777 1777 1778 if (viewport && 1778 if (viewport && 1779 1779 new_coord.x() >= (viewport->x()-epsilon) && new_coord.y() >= (viewport->y()-epsilon) && 1780 1780 new_coord.x() < (viewport->x()+viewport->width()-1.0+epsilon) && new_coord.y() <= (viewport->y()+viewport->height()-1.0+epsilon) ) 1781 1781 { 1782 1782 // osg::notify(osg::NOTICE)<<" in viewport "<<std::endl;; 1783 1783 1784 1784 local_x = new_coord.x(); 1785 1785 local_y = new_coord.y(); … … 1794 1794 } 1795 1795 } 1796 1796 1797 1797 local_x = x; 1798 1798 local_y = y; 1799 1799 1800 1800 return 0; 1801 1801 } … … 1805 1805 if (!_camera.valid()) return false; 1806 1806 1807 float local_x, local_y = 0.0; 1807 float local_x, local_y = 0.0; 1808 1808 const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); 1809 1809 if (!camera) camera = _camera.get(); 1810 1810 1811 1811 1812 1812 osgUtil::LineSegmentIntersector::CoordinateFrame cf = camera->getViewport() ? osgUtil::Intersector::WINDOW : osgUtil::Intersector::PROJECTION; … … 1826 1826 osgUtil::IntersectionVisitor iv(picker.get()); 1827 1827 iv.setTraversalMask(traversalMask); 1828 1829 1828 1829 1830 1830 #if 1 1831 1831 const_cast<osg::Camera*>(camera)->accept(iv); 1832 #else 1832 #else 1833 1833 1834 1834 // timing test code paths for comparing KdTree based intersections vs conventional intersections … … 1838 1838 1839 1839 const_cast<osg::Camera*>(camera)->accept(iv); 1840 1840 1841 1841 1842 1842 osg::Timer_t before = osg::Timer::instance()->tick(); … … 1856 1856 const_cast<osg::Camera*>(camera)->accept(iv); 1857 1857 osg::Timer_t after = osg::Timer::instance()->tick(); 1858 1858 1859 1859 int intersectsAfterConventional = picker->getIntersections().size(); 1860 1860 … … 1862 1862 double timeKdTree = osg::Timer::instance()->delta_m(after_dummy, after_kdTree_2); 1863 1863 double timeConventional = osg::Timer::instance()->delta_m(after_kdTree_2, after); 1864 1864 1865 1865 osg::notify(osg::NOTICE)<<"Using Dummy "<<timeDummy<<std::endl; 1866 1866 osg::notify(osg::NOTICE)<<" KdTrees "<<timeKdTree … … 1873 1873 osg::notify(osg::NOTICE)<<" Delta sans Traversal "<<(timeConventional-timeDummy)/(timeKdTree-timeDummy)<<std::endl; 1874 1874 osg::notify(osg::NOTICE)<<std::endl; 1875 #endif 1875 #endif 1876 1876 1877 1877 if (picker->containsIntersections()) … … 1890 1890 { 1891 1891 if (!_camera.valid() || nodePath.empty()) return false; 1892 1893 float local_x, local_y = 0.0; 1892 1893 float local_x, local_y = 0.0; 1894 1894 const osg::Camera* camera = getCameraContainingPosition(x, y, local_x, local_y); 1895 1895 if (!camera) camera = _camera.get(); 1896 1896 1897 1897 osg::Matrixd matrix; 1898 1898 if (nodePath.size()>1) … … 1901 1901 matrix = osg::computeLocalToWorld(prunedNodePath); 1902 1902 } 1903 1903 1904 1904 matrix.postMult(camera->getViewMatrix()); 1905 1905 matrix.postMult(camera->getProjectionMatrix()); … … 1919 1919 osg::Vec3d startVertex = osg::Vec3d(local_x,local_y,zNear) * inverse; 1920 1920 osg::Vec3d endVertex = osg::Vec3d(local_x,local_y,zFar) * inverse; 1921 1921 1922 1922 osg::ref_ptr< osgUtil::LineSegmentIntersector > picker = new osgUtil::LineSegmentIntersector(osgUtil::Intersector::MODEL, startVertex, endVertex); 1923 1923 1924 1924 osgUtil::IntersectionVisitor iv(picker.get()); 1925 1925 iv.setTraversalMask(traversalMask); … … 1938 1938 } 1939 1939 1940
