| | 645 | class FollowMouseCallback : public osgGA::GUIEventHandler, public osg::StateSet::Callback |
| | 646 | { |
| | 647 | public: |
| | 648 | |
| | 649 | FollowMouseCallback() |
| | 650 | { |
| | 651 | _updateTransparency = false; |
| | 652 | _updateAlphaCutOff = false; |
| | 653 | _updateSampleDensity = false; |
| | 654 | } |
| | 655 | |
| | 656 | FollowMouseCallback(const FollowMouseCallback&,const osg::CopyOp&) {} |
| | 657 | |
| | 658 | META_Object(osg,FollowMouseCallback); |
| | 659 | |
| | 660 | virtual void operator() (osg::StateSet* stateset, osg::NodeVisitor* nv) |
| | 661 | { |
| | 662 | osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv); |
| | 663 | if (nv->getVisitorType()==osg::NodeVisitor::EVENT_VISITOR || ev) |
| | 664 | { |
| | 665 | if (ev) |
| | 666 | { |
| | 667 | osgGA::GUIActionAdapter* aa = ev->getActionAdapter(); |
| | 668 | osgGA::EventVisitor::EventList& events = ev->getEventList(); |
| | 669 | for(osgGA::EventVisitor::EventList::iterator itr=events.begin(); |
| | 670 | itr!=events.end(); |
| | 671 | ++itr) |
| | 672 | { |
| | 673 | handle(*(*itr), *aa, stateset, ev); |
| | 674 | } |
| | 675 | } |
| | 676 | } |
| | 677 | } |
| | 678 | |
| | 679 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&, osg::Object* object, osg::NodeVisitor*) |
| | 680 | { |
| | 681 | osg::StateSet* stateset = dynamic_cast<osg::StateSet*>(object); |
| | 682 | if (!stateset) return false; |
| | 683 | |
| | 684 | switch(ea.getEventType()) |
| | 685 | { |
| | 686 | case(osgGA::GUIEventAdapter::MOVE): |
| | 687 | case(osgGA::GUIEventAdapter::DRAG): |
| | 688 | { |
| | 689 | float v = ea.getY()*0.5f+0.5f; |
| | 690 | osg::Uniform* uniform = 0; |
| | 691 | if (_updateTransparency && (uniform = stateset->getUniform("transparency"))) uniform->set(v); |
| | 692 | if (_updateAlphaCutOff && (uniform = stateset->getUniform("alphaCutOff"))) uniform->set(v); |
| | 693 | if (_updateSampleDensity && (uniform = stateset->getUniform("sampleDensity"))) uniform->set(powf(v,5)); |
| | 694 | break; |
| | 695 | } |
| | 696 | case(osgGA::GUIEventAdapter::KEYDOWN): |
| | 697 | { |
| | 698 | if (ea.getKey()=='t') _updateTransparency = true; |
| | 699 | if (ea.getKey()=='a') _updateAlphaCutOff = true; |
| | 700 | if (ea.getKey()=='d') _updateSampleDensity = true; |
| | 701 | break; |
| | 702 | } |
| | 703 | case(osgGA::GUIEventAdapter::KEYUP): |
| | 704 | { |
| | 705 | if (ea.getKey()=='t') _updateTransparency = false; |
| | 706 | if (ea.getKey()=='a') _updateAlphaCutOff = false; |
| | 707 | if (ea.getKey()=='d') _updateSampleDensity = false; |
| | 708 | break; |
| | 709 | } |
| | 710 | default: |
| | 711 | break; |
| | 712 | } |
| | 713 | return false; |
| | 714 | } |
| | 715 | |
| | 716 | virtual void accept(osgGA::GUIEventHandlerVisitor& v) |
| | 717 | { |
| | 718 | v.visit(*this); |
| | 719 | } |
| | 720 | |
| | 721 | bool _updateTransparency; |
| | 722 | bool _updateAlphaCutOff; |
| | 723 | bool _updateSampleDensity; |
| | 724 | |
| | 725 | }; |
| | 726 | |