| 14 | | |
| 15 | | |
| 16 | | osg::Node* createInteractiveQuad(const osg::Vec3& origin, osg::Vec3& widthAxis, osg::Vec3& heightAxis, |
| 17 | | osg::Image* image) |
| 18 | | { |
| 19 | | bool flip = image->getOrigin()==osg::Image::TOP_LEFT; |
| 20 | | |
| 21 | | osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(origin, widthAxis, heightAxis, |
| 22 | | 0.0f, flip ? 1.0f : 0.0f , 1.0f, flip ? 0.0f : 1.0f); |
| 23 | | |
| 24 | | osg::Texture2D* texture = new osg::Texture2D(image); |
| 25 | | texture->setResizeNonPowerOfTwoHint(false); |
| 26 | | texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
| 27 | | texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); |
| 28 | | texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); |
| 29 | | |
| 30 | | pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, |
| 31 | | texture, |
| 32 | | osg::StateAttribute::ON); |
| 33 | | |
| 34 | | |
| 35 | | |
| 36 | | osg::ref_ptr<osgViewer::InteractiveImageHandler> callback = new osgViewer::InteractiveImageHandler(image); |
| 37 | | |
| 38 | | pictureQuad->setEventCallback(callback.get()); |
| 39 | | pictureQuad->setCullCallback(callback.get()); |
| 40 | | |
| 41 | | osg::Geode* geode = new osg::Geode; |
| 42 | | geode->addDrawable(pictureQuad); |
| 43 | | |
| 44 | | return geode; |
| 45 | | } |
| 80 | | osg::ArgumentParser arguments(&argc, argv); |
| 81 | | osgViewer::Viewer viewer; |
| 82 | | |
| 83 | | typedef std::list< osg::ref_ptr<osg::Image> > Images; |
| 84 | | Images images; |
| | 50 | osgWidget::GeometryHints hints(osg::Vec3(1.0f,0.0f,0.0f), |
| | 51 | osg::Vec3(1.0f,0.0f,0.0f), |
| | 52 | osg::Vec3(0.0f,0.0f,1.0f), |
| | 53 | osgWidget::GeometryHints::RESIZE_HEIGHT_TO_MAINTAINCE_ASPECT_RATIO); |
| 98 | | bool xyPlane = false; |
| 99 | | |
| 100 | | osg::Group* group = new osg::Group; |
| 101 | | |
| 102 | | osg::Vec3 origin = osg::Vec3(0.0f,0.0f,0.0f); |
| 103 | | for(Images::iterator itr = images.begin(); |
| 104 | | itr != images.end(); |
| 105 | | ++itr) |
| 106 | | { |
| 107 | | osg::Image* image = itr->get(); |
| 108 | | float width = 1.0; |
| 109 | | float height = float(image->t())/float(image->s()); |
| 110 | | osg::Vec3 widthAxis = osg::Vec3(width,0.0f,0.0f); |
| 111 | | osg::Vec3 heightAxis = xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height); |
| 112 | | group->addChild(createInteractiveQuad(origin, widthAxis, heightAxis, image)); |
| 113 | | |
| 114 | | origin += widthAxis*1.1f; |
| 115 | | } |
| 116 | | |
| 117 | | viewer.setSceneData(group); |
| | 71 | viewer.setSceneData(group.get()); |