| 704 | | |
| 705 | | osg::Node* ForestTechniqueManager::createScene() |
| | 715 | osg::Node* ForestTechniqueManager::createHUDWithText(const std::string& str) |
| | 716 | { |
| | 717 | osg::Geode* geode = new osg::Geode(); |
| | 718 | |
| | 719 | std::string timesFont("fonts/arial.ttf"); |
| | 720 | |
| | 721 | // turn lighting off for the text and disable depth test to ensure its always ontop. |
| | 722 | osg::StateSet* stateset = geode->getOrCreateStateSet(); |
| | 723 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
| | 724 | |
| | 725 | // or disable depth test, and make sure that the hud is drawn after everything |
| | 726 | // else so that it always appears ontop. |
| | 727 | stateset->setMode(GL_DEPTH_TEST,osg::StateAttribute::OFF); |
| | 728 | stateset->setRenderBinDetails(11,"RenderBin"); |
| | 729 | |
| | 730 | osg::Vec3 position(150.0f,800.0f,0.0f); |
| | 731 | osg::Vec3 delta(0.0f,-120.0f,0.0f); |
| | 732 | |
| | 733 | { |
| | 734 | osgText::Text* text = new osgText::Text; |
| | 735 | geode->addDrawable( text ); |
| | 736 | |
| | 737 | text->setFont(timesFont); |
| | 738 | text->setPosition(position); |
| | 739 | text->setText(str); |
| | 740 | |
| | 741 | position += delta; |
| | 742 | } |
| | 743 | |
| | 744 | |
| | 745 | // create the hud. |
| | 746 | osg::MatrixTransform* modelview_abs = new osg::MatrixTransform; |
| | 747 | modelview_abs->setReferenceFrame(osg::Transform::RELATIVE_TO_ABSOLUTE); |
| | 748 | modelview_abs->setMatrix(osg::Matrix::identity()); |
| | 749 | modelview_abs->addChild(geode); |
| | 750 | |
| | 751 | osg::Projection* projection = new osg::Projection; |
| | 752 | projection->setMatrix(osg::Matrix::ortho2D(0,1280,0,1024)); |
| | 753 | projection->addChild(modelview_abs); |
| | 754 | |
| | 755 | return projection; |
| | 756 | } |
| | 757 | |
| | 758 | osg::Node* ForestTechniqueManager::createScene(unsigned int numTreesToCreates) |
| 749 | | std::cout<<"Creating billboard based forest..."; |
| 750 | | _techniqueSwitch->addChild(createBillboardGraph(cell.get(),dstate)); |
| 751 | | std::cout<<"done."<<std::endl; |
| 752 | | |
| 753 | | std::cout<<"Creating double quad based forest..."; |
| 754 | | _techniqueSwitch->addChild(createXGraph(cell.get(),dstate)); |
| 755 | | std::cout<<"done."<<std::endl; |
| 756 | | |
| 757 | | std::cout<<"Creating transform based forest..."; |
| 758 | | _techniqueSwitch->addChild(createTransformGraph(cell.get(),dstate)); |
| 759 | | std::cout<<"done."<<std::endl; |
| | 801 | { |
| | 802 | std::cout<<"Creating billboard based forest..."; |
| | 803 | osg::Group* group = new osg::Group; |
| | 804 | group->addChild(createBillboardGraph(cell.get(),dstate)); |
| | 805 | group->addChild(createHUDWithText("Using osg::Billboard's to create a forest\n\nPress left cursor key to select osg::MatrixTransform based forest\nPress right cursor key to select double quad based forest")); |
| | 806 | _techniqueSwitch->addChild(group); |
| | 807 | std::cout<<"done."<<std::endl; |
| | 808 | } |
| | 809 | |
| | 810 | { |
| | 811 | std::cout<<"Creating billboard based forest..."; |
| | 812 | osg::Group* group = new osg::Group; |
| | 813 | group->addChild(createXGraph(cell.get(),dstate)); |
| | 814 | group->addChild(createHUDWithText("Using double quads to create a forest\n\nPress left cursor key to select osg::Billboard based forest\nPress right cursor key to select osg::MatrixTransform based forest\n")); |
| | 815 | _techniqueSwitch->addChild(group); |
| | 816 | std::cout<<"done."<<std::endl; |
| | 817 | } |
| | 818 | |
| | 819 | { |
| | 820 | std::cout<<"Creating billboard based forest..."; |
| | 821 | osg::Group* group = new osg::Group; |
| | 822 | group->addChild(createTransformGraph(cell.get(),dstate)); |
| | 823 | group->addChild(createHUDWithText("Using osg::MatrixTransform's to create a forest\n\nPress left cursor key to select double quad based forest\nPress right cursor key to select osg::Billboard based forest")); |
| | 824 | _techniqueSwitch->addChild(group); |
| | 825 | std::cout<<"done."<<std::endl; |
| | 826 | } |