| [6941] | 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| [3762] | 19 | #include <osg/Geode> |
|---|
| 20 | #include <osg/Group> |
|---|
| 21 | #include <osg/Notify> |
|---|
| 22 | #include <osg/LogicOp> |
|---|
| 23 | |
|---|
| 24 | #include <osgDB/Registry> |
|---|
| 25 | #include <osgDB/ReadFile> |
|---|
| 26 | |
|---|
| [5927] | 27 | #include <osgViewer/Viewer> |
|---|
| [3762] | 28 | |
|---|
| 29 | #include <osgUtil/Optimizer> |
|---|
| 30 | |
|---|
| [5927] | 31 | #include <iostream> |
|---|
| 32 | |
|---|
| [4739] | 33 | const int _ops_nb=16; |
|---|
| 34 | const osg::LogicOp::Opcode _operations[_ops_nb]= |
|---|
| [4805] | 35 | { |
|---|
| 36 | osg::LogicOp::CLEAR, |
|---|
| 37 | osg::LogicOp::SET, |
|---|
| 38 | osg::LogicOp::COPY, |
|---|
| 39 | osg::LogicOp::COPY_INVERTED, |
|---|
| 40 | osg::LogicOp::NOOP, |
|---|
| 41 | osg::LogicOp::INVERT, |
|---|
| 42 | osg::LogicOp::AND, |
|---|
| 43 | osg::LogicOp::NAND, |
|---|
| 44 | osg::LogicOp::OR, |
|---|
| 45 | osg::LogicOp::NOR, |
|---|
| 46 | osg::LogicOp::XOR, |
|---|
| 47 | osg::LogicOp::EQUIV, |
|---|
| 48 | osg::LogicOp::AND_REVERSE, |
|---|
| 49 | osg::LogicOp::AND_INVERTED, |
|---|
| 50 | osg::LogicOp::OR_REVERSE, |
|---|
| 51 | osg::LogicOp::OR_INVERTED |
|---|
| [4739] | 52 | }; |
|---|
| [3762] | 53 | |
|---|
| [4739] | 54 | const char* _ops_name[_ops_nb]= |
|---|
| [4805] | 55 | { |
|---|
| 56 | "osg::LogicOp::CLEAR", |
|---|
| 57 | "osg::LogicOp::SET", |
|---|
| 58 | "osg::LogicOp::COPY", |
|---|
| 59 | "osg::LogicOp::COPY_INVERTED", |
|---|
| 60 | "osg::LogicOp::NOOP", |
|---|
| 61 | "osg::LogicOp::INVERT", |
|---|
| 62 | "osg::LogicOp::AND", |
|---|
| 63 | "osg::LogicOp::NAND", |
|---|
| 64 | "osg::LogicOp::OR", |
|---|
| 65 | "osg::LogicOp::NOR", |
|---|
| 66 | "osg::LogicOp::XOR", |
|---|
| 67 | "osg::LogicOp::EQUIV", |
|---|
| 68 | "osg::LogicOp::AND_REVERSE", |
|---|
| 69 | "osg::LogicOp::AND_INVERTED", |
|---|
| 70 | "osg::LogicOp::OR_REVERSE", |
|---|
| 71 | "osg::LogicOp::OR_INVERTED" |
|---|
| [4739] | 72 | }; |
|---|
| 73 | |
|---|
| [3925] | 74 | class TechniqueEventHandler : public osgGA::GUIEventHandler |
|---|
| [3762] | 75 | { |
|---|
| 76 | public: |
|---|
| 77 | |
|---|
| 78 | TechniqueEventHandler(osg::LogicOp* logicOp) { _logicOp =logicOp;_ops_index=_ops_nb-1;} |
|---|
| 79 | TechniqueEventHandler() { std::cerr<<"Error, can't initialize it!";} |
|---|
| 80 | |
|---|
| 81 | META_Object(osglogicopApp,TechniqueEventHandler); |
|---|
| 82 | |
|---|
| 83 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&); |
|---|
| 84 | |
|---|
| 85 | virtual void getUsage(osg::ApplicationUsage& usage) const; |
|---|
| 86 | |
|---|
| 87 | protected: |
|---|
| 88 | |
|---|
| 89 | ~TechniqueEventHandler() {} |
|---|
| 90 | |
|---|
| 91 | TechniqueEventHandler(const TechniqueEventHandler&,const osg::CopyOp&) {} |
|---|
| 92 | |
|---|
| [4805] | 93 | osg::LogicOp* _logicOp; |
|---|
| 94 | int _ops_index; |
|---|
| [3762] | 95 | |
|---|
| 96 | }; |
|---|
| 97 | |
|---|
| 98 | bool TechniqueEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&) |
|---|
| 99 | { |
|---|
| 100 | switch(ea.getEventType()) |
|---|
| 101 | { |
|---|
| 102 | case(osgGA::GUIEventAdapter::KEYDOWN): |
|---|
| 103 | { |
|---|
| 104 | if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Right || |
|---|
| 105 | ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Right) |
|---|
| 106 | { |
|---|
| [4805] | 107 | _ops_index++; |
|---|
| 108 | if (_ops_index>=_ops_nb) _ops_index=0; |
|---|
| 109 | _logicOp->setOpcode(_operations[_ops_index]); |
|---|
| 110 | std::cout<<"Operation name = "<<_ops_name[_ops_index]<<std::endl; |
|---|
| [3762] | 111 | return true; |
|---|
| 112 | } |
|---|
| 113 | else if (ea.getKey()==osgGA::GUIEventAdapter::KEY_Left || |
|---|
| 114 | ea.getKey()==osgGA::GUIEventAdapter::KEY_KP_Left) |
|---|
| 115 | { |
|---|
| [4805] | 116 | _ops_index--; |
|---|
| 117 | if (_ops_index<0) _ops_index=_ops_nb-1; |
|---|
| 118 | _logicOp->setOpcode(_operations[_ops_index]); |
|---|
| 119 | std::cout<<"Operation name = "<<_ops_name[_ops_index]<<std::endl; |
|---|
| [3762] | 120 | return true; |
|---|
| 121 | } |
|---|
| 122 | return false; |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | default: |
|---|
| 126 | return false; |
|---|
| 127 | } |
|---|
| 128 | } |
|---|
| 129 | |
|---|
| 130 | void TechniqueEventHandler::getUsage(osg::ApplicationUsage& usage) const |
|---|
| 131 | { |
|---|
| 132 | usage.addKeyboardMouseBinding("- or Left Arrow","Advance to next opcode"); |
|---|
| 133 | usage.addKeyboardMouseBinding("+ or Right Array","Move to previous opcode"); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | int main( int argc, char **argv ) |
|---|
| 140 | { |
|---|
| 141 | |
|---|
| 142 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | osg::Node* loadedModel = osgDB::readNodeFiles(arguments); |
|---|
| [6916] | 146 | |
|---|
| 147 | |
|---|
| [12529] | 148 | if (!loadedModel) loadedModel = osgDB::readNodeFile("glider.osgt"); |
|---|
| [6916] | 149 | |
|---|
| [3762] | 150 | if (!loadedModel) |
|---|
| 151 | { |
|---|
| [5927] | 152 | osg::notify(osg::NOTICE)<<"Please specify model filename on the command line."<<std::endl; |
|---|
| [3762] | 153 | return 1; |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | osg::Group* root = new osg::Group; |
|---|
| 157 | root->addChild(loadedModel); |
|---|
| 158 | |
|---|
| [4805] | 159 | osg::StateSet* stateset = new osg::StateSet; |
|---|
| 160 | osg::LogicOp* logicOp = new osg::LogicOp(osg::LogicOp::OR_INVERTED); |
|---|
| 161 | |
|---|
| [3762] | 162 | stateset->setAttributeAndModes(logicOp,osg::StateAttribute::OVERRIDE|osg::StateAttribute::ON); |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | stateset->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); |
|---|
| 166 | |
|---|
| [4805] | 167 | |
|---|
| [3762] | 168 | loadedModel->setStateSet(stateset); |
|---|
| 169 | |
|---|
| [5927] | 170 | |
|---|
| 171 | osgViewer::Viewer viewer; |
|---|
| [3762] | 172 | |
|---|
| [5927] | 173 | viewer.addEventHandler(new TechniqueEventHandler(logicOp)); |
|---|
| [3762] | 174 | |
|---|
| 175 | |
|---|
| 176 | osgUtil::Optimizer optimzer; |
|---|
| 177 | optimzer.optimize(root); |
|---|
| 178 | |
|---|
| 179 | |
|---|
| 180 | viewer.setSceneData( root ); |
|---|
| 181 | |
|---|
| [5927] | 182 | return viewer.run(); |
|---|
| [3762] | 183 | } |
|---|