2008-11-13 23:35:08 +08:00
|
|
|
#include <osg/Image>
|
|
|
|
#include <osg/Geometry>
|
|
|
|
#include <osg/Texture2D>
|
|
|
|
#include <osg/io_utils>
|
2008-11-18 21:36:47 +08:00
|
|
|
#include <osg/GraphicsThread>
|
2008-11-13 23:35:08 +08:00
|
|
|
|
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
#include <osgViewer/ViewerEventHandlers>
|
2008-11-17 23:49:24 +08:00
|
|
|
#include <osgGA/TrackballManipulator>
|
2008-11-13 23:35:08 +08:00
|
|
|
|
|
|
|
#include <osgDB/FileUtils>
|
|
|
|
#include <osgDB/FileNameUtils>
|
|
|
|
#include <osgDB/ReadFile>
|
|
|
|
|
2008-11-17 23:49:24 +08:00
|
|
|
#include <nsGUIEvent.h>
|
2008-11-15 00:48:07 +08:00
|
|
|
|
|
|
|
#include "llmozlib2.h"
|
2008-11-13 23:35:08 +08:00
|
|
|
|
2008-11-20 00:58:32 +08:00
|
|
|
#include "UBrowser.h"
|
2008-11-18 01:58:59 +08:00
|
|
|
|
|
|
|
|
2008-11-17 23:49:24 +08:00
|
|
|
osg::Node* createInteractiveQuad(const osg::Vec3& origin, osg::Vec3& widthAxis, osg::Vec3& heightAxis,
|
|
|
|
osg::Image* image)
|
|
|
|
{
|
|
|
|
bool flip = image->getOrigin()==osg::Image::TOP_LEFT;
|
|
|
|
|
|
|
|
osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(origin, widthAxis, heightAxis,
|
|
|
|
0.0f, flip ? 1.0f : 0.0f , 1.0f, flip ? 0.0f : 1.0f);
|
|
|
|
|
|
|
|
osg::Texture2D* texture = new osg::Texture2D(image);
|
|
|
|
texture->setResizeNonPowerOfTwoHint(false);
|
|
|
|
texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR);
|
|
|
|
texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
|
|
|
|
|
|
|
|
pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0,
|
|
|
|
texture,
|
|
|
|
osg::StateAttribute::ON);
|
|
|
|
|
|
|
|
pictureQuad->setEventCallback(new osgViewer::InteractiveImageHandler(image));
|
|
|
|
|
|
|
|
osg::Geode* geode = new osg::Geode;
|
|
|
|
geode->addDrawable(pictureQuad);
|
|
|
|
|
|
|
|
return geode;
|
|
|
|
}
|
2008-11-15 00:48:07 +08:00
|
|
|
|
|
|
|
|
2008-11-17 23:49:24 +08:00
|
|
|
int main( int argc, char* argv[] )
|
|
|
|
{
|
|
|
|
osg::ArgumentParser arguments(&argc, argv);
|
2008-11-18 01:58:59 +08:00
|
|
|
|
2008-11-20 00:58:32 +08:00
|
|
|
osgWidget::BrowserManager::instance()->init(arguments[0]);
|
2008-11-17 23:49:24 +08:00
|
|
|
|
|
|
|
osgViewer::Viewer viewer(arguments);
|
|
|
|
|
2008-11-20 00:58:32 +08:00
|
|
|
typedef std::list< osg::ref_ptr<osg::Image> > Images;
|
2008-11-17 23:49:24 +08:00
|
|
|
Images images;
|
|
|
|
|
|
|
|
for(int i=1; i<arguments.argc(); ++i)
|
|
|
|
{
|
|
|
|
if (!arguments.isOption(i))
|
|
|
|
{
|
2008-11-20 00:58:32 +08:00
|
|
|
std::string url_browser = std::string(arguments[i])+std::string(".browser");
|
|
|
|
osg::ref_ptr<osg::Image> image = osgDB::readImageFile(url_browser);
|
|
|
|
if (image.valid()) images.push_back(image.get());
|
2008-11-17 23:49:24 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool xyPlane = false;
|
|
|
|
|
|
|
|
osg::Group* group = new osg::Group;
|
|
|
|
|
|
|
|
osg::Vec3 origin = osg::Vec3(0.0f,0.0f,0.0f);
|
|
|
|
for(Images::iterator itr = images.begin();
|
|
|
|
itr != images.end();
|
|
|
|
++itr)
|
|
|
|
{
|
|
|
|
osg::Image* image = itr->get();
|
|
|
|
float width = 1.0;
|
|
|
|
float height = float(image->t())/float(image->s());
|
|
|
|
|
|
|
|
osg::Vec3 widthAxis = osg::Vec3(width,0.0f,0.0f);
|
|
|
|
osg::Vec3 heightAxis = xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height);
|
|
|
|
|
|
|
|
group->addChild(createInteractiveQuad(origin, widthAxis, heightAxis, image));
|
|
|
|
|
|
|
|
origin += widthAxis*1.1f;
|
|
|
|
}
|
|
|
|
|
|
|
|
viewer.setSceneData(group);
|
|
|
|
|
|
|
|
viewer.addEventHandler(new osgViewer::StatsHandler);
|
|
|
|
|
2008-11-18 21:36:47 +08:00
|
|
|
return viewer.run();
|
2008-11-15 00:48:07 +08:00
|
|
|
}
|