Changeset 7539 for OpenSceneGraph/trunk/examples/osgshadow/osgshadow.cpp
- Timestamp:
- 10/02/07 23:45:09 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
OpenSceneGraph/trunk/examples/osgshadow/osgshadow.cpp
r7499 r7539 666 666 osg::ref_ptr<osgShadow::ShadowMap> sm = new osgShadow::ShadowMap; 667 667 shadowedScene->setShadowTechnique(sm.get()); 668 } 668 669 int mapres = 1024; 670 while (arguments.read("--mapres", mapres)) 671 sm->setTextureSize(osg::Vec2s(mapres,mapres)); 672 } 669 673 670 674 osg::ref_ptr<osg::Node> model = osgDB::readNodeFiles(arguments); … … 716 720 osg::ref_ptr<osg::LightSource> ls = new osg::LightSource; 717 721 ls->getLight()->setPosition(lightpos); 722 723 bool spotlight = false; 724 if (arguments.read("--spotLight")) 725 { 726 spotlight = true; 727 728 osg::Vec3 center = bb.center(); 729 osg::Vec3 lightdir = center - osg::Vec3(lightpos.x(), lightpos.y(), lightpos.z()); 730 lightdir.normalize(); 731 ls->getLight()->setDirection(lightdir); 732 ls->getLight()->setSpotCutoff(30.0f); 733 734 //set the LightSource, only for checking, there is only 1 light in the scene 735 dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique())->setLight(ls.get()); 736 } 737 718 738 if ( arguments.read("--coloured-light")) 719 739 { … … 731 751 732 752 viewer.setSceneData(shadowedScene.get()); 733 753 734 754 // create the windows and run the threads. 735 755 viewer.realize(); 756 757 // it is done after viewer.realize() so that the windows are already initialized 758 if ( arguments.read("--debugHUD")) 759 { 760 osgViewer::Viewer::Windows windows; 761 viewer.getWindows(windows); 762 763 if (windows.empty()) return 1; 764 765 osgShadow::ShadowMap* sm = dynamic_cast<osgShadow::ShadowMap*>(shadowedScene->getShadowTechnique()); 766 osg::ref_ptr<osg::Camera> hudCamera = sm->makeDebugHUD(); 767 768 // set up cameras to rendering on the first window available. 769 hudCamera->setGraphicsContext(windows[0]); 770 hudCamera->setViewport(0,0,windows[0]->getTraits()->width, windows[0]->getTraits()->height); 771 772 viewer.addSlave(hudCamera.get(), false); 773 } 774 736 775 737 776 // osgDB::writeNodeFile(*group,"test.osg"); … … 744 783 if (postionalLight) 745 784 { 746 lightpos.set(bb.center().x()+sinf(t)*bb.radius(), bb.center().y() + cosf(t)*bb.radius(), bb.zMax() + bb.radius() ,1.0f);785 lightpos.set(bb.center().x()+sinf(t)*bb.radius(), bb.center().y() + cosf(t)*bb.radius(), bb.zMax() + bb.radius()*2.0f ,1.0f); 747 786 } 748 787 else … … 753 792 754 793 osg::Vec3f lightDir(-lightpos.x(),-lightpos.y(),-lightpos.z()); 794 if(spotlight) 795 lightDir = osg::Vec3(bb.center().x()+sinf(t)*bb.radius()/2.0, bb.center().y() + cosf(t)*bb.radius()/2.0, bb.center().z()) 796 - osg::Vec3(lightpos.x(), lightpos.y(), lightpos.z()) ; 755 797 lightDir.normalize(); 756 798 ls->getLight()->setDirection(lightDir);
