| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | |
|---|
| 16 | |
|---|
| 17 | |
|---|
| 18 | |
|---|
| 19 | #include <osgViewer/Viewer> |
|---|
| 20 | #include <osgViewer/ViewerEventHandlers> |
|---|
| 21 | |
|---|
| 22 | #include <osgDB/ReadFile> |
|---|
| 23 | |
|---|
| 24 | #include <osg/Geode> |
|---|
| 25 | #include <osg/Geometry> |
|---|
| 26 | #include <osg/StateSet> |
|---|
| 27 | #include <osg/Material> |
|---|
| 28 | #include <osg/Texture2D> |
|---|
| 29 | #include <osg/TextureRectangle> |
|---|
| 30 | #include <osg/TextureCubeMap> |
|---|
| 31 | #include <osg/TexMat> |
|---|
| 32 | #include <osg/CullFace> |
|---|
| 33 | #include <osg/ImageStream> |
|---|
| 34 | #include <osg/io_utils> |
|---|
| 35 | |
|---|
| 36 | #include <osgGA/TrackballManipulator> |
|---|
| 37 | #include <osgGA/StateSetManipulator> |
|---|
| 38 | #include <osgGA/EventVisitor> |
|---|
| 39 | |
|---|
| 40 | #include <iostream> |
|---|
| 41 | |
|---|
| 42 | osg::ImageStream* s_imageStream = 0; |
|---|
| 43 | class MovieEventHandler : public osgGA::GUIEventHandler |
|---|
| 44 | { |
|---|
| 45 | public: |
|---|
| 46 | |
|---|
| 47 | MovieEventHandler():_trackMouse(false),_playToggle(true) {} |
|---|
| 48 | |
|---|
| 49 | void setMouseTracking(bool track) { _trackMouse = track; } |
|---|
| 50 | bool getMouseTracking() const { return _trackMouse; } |
|---|
| 51 | |
|---|
| 52 | void set(osg::Node* node); |
|---|
| 53 | |
|---|
| 54 | virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv); |
|---|
| 55 | |
|---|
| 56 | virtual void getUsage(osg::ApplicationUsage& usage) const; |
|---|
| 57 | |
|---|
| 58 | typedef std::vector< osg::observer_ptr<osg::ImageStream> > ImageStreamList; |
|---|
| 59 | |
|---|
| 60 | protected: |
|---|
| 61 | |
|---|
| 62 | virtual ~MovieEventHandler() {} |
|---|
| 63 | |
|---|
| 64 | class FindImageStreamsVisitor : public osg::NodeVisitor |
|---|
| 65 | { |
|---|
| 66 | public: |
|---|
| 67 | FindImageStreamsVisitor(ImageStreamList& imageStreamList): |
|---|
| 68 | _imageStreamList(imageStreamList) {} |
|---|
| 69 | |
|---|
| 70 | virtual void apply(osg::Geode& geode) |
|---|
| 71 | { |
|---|
| 72 | apply(geode.getStateSet()); |
|---|
| 73 | |
|---|
| 74 | for(unsigned int i=0;i<geode.getNumDrawables();++i) |
|---|
| 75 | { |
|---|
| 76 | apply(geode.getDrawable(i)->getStateSet()); |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | traverse(geode); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| 82 | virtual void apply(osg::Node& node) |
|---|
| 83 | { |
|---|
| 84 | apply(node.getStateSet()); |
|---|
| 85 | traverse(node); |
|---|
| 86 | } |
|---|
| 87 | |
|---|
| 88 | inline void apply(osg::StateSet* stateset) |
|---|
| 89 | { |
|---|
| 90 | if (!stateset) return; |
|---|
| 91 | |
|---|
| 92 | osg::StateAttribute* attr = stateset->getTextureAttribute(0,osg::StateAttribute::TEXTURE); |
|---|
| 93 | if (attr) |
|---|
| 94 | { |
|---|
| 95 | osg::Texture2D* texture2D = dynamic_cast<osg::Texture2D*>(attr); |
|---|
| 96 | if (texture2D) apply(dynamic_cast<osg::ImageStream*>(texture2D->getImage())); |
|---|
| 97 | |
|---|
| 98 | osg::TextureRectangle* textureRec = dynamic_cast<osg::TextureRectangle*>(attr); |
|---|
| 99 | if (textureRec) apply(dynamic_cast<osg::ImageStream*>(textureRec->getImage())); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | |
|---|
| 103 | inline void apply(osg::ImageStream* imagestream) |
|---|
| 104 | { |
|---|
| 105 | if (imagestream) |
|---|
| 106 | { |
|---|
| 107 | _imageStreamList.push_back(imagestream); |
|---|
| 108 | s_imageStream = imagestream; |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | ImageStreamList& _imageStreamList; |
|---|
| 113 | }; |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | bool _playToggle; |
|---|
| 117 | bool _trackMouse; |
|---|
| 118 | ImageStreamList _imageStreamList; |
|---|
| 119 | |
|---|
| 120 | }; |
|---|
| 121 | |
|---|
| 122 | |
|---|
| 123 | |
|---|
| 124 | void MovieEventHandler::set(osg::Node* node) |
|---|
| 125 | { |
|---|
| 126 | _imageStreamList.clear(); |
|---|
| 127 | if (node) |
|---|
| 128 | { |
|---|
| 129 | FindImageStreamsVisitor fisv(_imageStreamList); |
|---|
| 130 | node->accept(fisv); |
|---|
| 131 | } |
|---|
| 132 | } |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | bool MovieEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa, osg::Object*, osg::NodeVisitor* nv) |
|---|
| 136 | { |
|---|
| 137 | switch(ea.getEventType()) |
|---|
| 138 | { |
|---|
| 139 | case(osgGA::GUIEventAdapter::MOVE): |
|---|
| 140 | case(osgGA::GUIEventAdapter::PUSH): |
|---|
| 141 | case(osgGA::GUIEventAdapter::RELEASE): |
|---|
| 142 | { |
|---|
| 143 | if (_trackMouse) |
|---|
| 144 | { |
|---|
| 145 | osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa); |
|---|
| 146 | osgUtil::LineSegmentIntersector::Intersections intersections; |
|---|
| 147 | bool foundIntersection = view==0 ? false : |
|---|
| 148 | (nv==0 ? view->computeIntersections(ea.getX(), ea.getY(), intersections) : |
|---|
| 149 | view->computeIntersections(ea.getX(), ea.getY(), nv->getNodePath(), intersections)); |
|---|
| 150 | |
|---|
| 151 | if (foundIntersection) |
|---|
| 152 | { |
|---|
| 153 | |
|---|
| 154 | |
|---|
| 155 | const osgUtil::LineSegmentIntersector::Intersection& intersection = *(intersections.begin()); |
|---|
| 156 | osg::Drawable* drawable = intersection.drawable.get(); |
|---|
| 157 | osg::Geometry* geometry = drawable ? drawable->asGeometry() : 0; |
|---|
| 158 | osg::Vec3Array* vertices = geometry ? dynamic_cast<osg::Vec3Array*>(geometry->getVertexArray()) : 0; |
|---|
| 159 | if (vertices) |
|---|
| 160 | { |
|---|
| 161 | |
|---|
| 162 | const osgUtil::LineSegmentIntersector::Intersection::IndexList& indices = intersection.indexList; |
|---|
| 163 | const osgUtil::LineSegmentIntersector::Intersection::RatioList& ratios = intersection.ratioList; |
|---|
| 164 | |
|---|
| 165 | if (indices.size()==3 && ratios.size()==3) |
|---|
| 166 | { |
|---|
| 167 | unsigned int i1 = indices[0]; |
|---|
| 168 | unsigned int i2 = indices[1]; |
|---|
| 169 | unsigned int i3 = indices[2]; |
|---|
| 170 | |
|---|
| 171 | float r1 = ratios[0]; |
|---|
| 172 | float r2 = ratios[1]; |
|---|
| 173 | float r3 = ratios[2]; |
|---|
| 174 | |
|---|
| 175 | osg::Array* texcoords = (geometry->getNumTexCoordArrays()>0) ? geometry->getTexCoordArray(0) : 0; |
|---|
| 176 | osg::Vec2Array* texcoords_Vec2Array = dynamic_cast<osg::Vec2Array*>(texcoords); |
|---|
| 177 | if (texcoords_Vec2Array) |
|---|
| 178 | { |
|---|
| 179 | |
|---|
| 180 | osg::Vec2 tc1 = (*texcoords_Vec2Array)[i1]; |
|---|
| 181 | osg::Vec2 tc2 = (*texcoords_Vec2Array)[i2]; |
|---|
| 182 | osg::Vec2 tc3 = (*texcoords_Vec2Array)[i3]; |
|---|
| 183 | osg::Vec2 tc = tc1*r1 + tc2*r2 + tc3*r3; |
|---|
| 184 | |
|---|
| 185 | osg::notify(osg::NOTICE)<<"We hit tex coords "<<tc<<std::endl; |
|---|
| 186 | |
|---|
| 187 | } |
|---|
| 188 | } |
|---|
| 189 | else |
|---|
| 190 | { |
|---|
| 191 | osg::notify(osg::NOTICE)<<"Intersection has insufficient indices to work with"; |
|---|
| 192 | } |
|---|
| 193 | |
|---|
| 194 | } |
|---|
| 195 | } |
|---|
| 196 | else |
|---|
| 197 | { |
|---|
| 198 | osg::notify(osg::NOTICE)<<"No intersection"<<std::endl; |
|---|
| 199 | } |
|---|
| 200 | } |
|---|
| 201 | break; |
|---|
| 202 | } |
|---|
| 203 | case(osgGA::GUIEventAdapter::KEYDOWN): |
|---|
| 204 | { |
|---|
| 205 | if (ea.getKey()=='p') |
|---|
| 206 | { |
|---|
| 207 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 208 | itr!=_imageStreamList.end(); |
|---|
| 209 | ++itr) |
|---|
| 210 | { |
|---|
| 211 | _playToggle = !_playToggle; |
|---|
| 212 | if ( _playToggle ) |
|---|
| 213 | { |
|---|
| 214 | |
|---|
| 215 | std::cout<<"Play"<<std::endl; |
|---|
| 216 | (*itr)->play(); |
|---|
| 217 | } |
|---|
| 218 | else |
|---|
| 219 | { |
|---|
| 220 | |
|---|
| 221 | std::cout<<"Pause"<<std::endl; |
|---|
| 222 | (*itr)->pause(); |
|---|
| 223 | } |
|---|
| 224 | } |
|---|
| 225 | return true; |
|---|
| 226 | } |
|---|
| 227 | else if (ea.getKey()=='r') |
|---|
| 228 | { |
|---|
| 229 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 230 | itr!=_imageStreamList.end(); |
|---|
| 231 | ++itr) |
|---|
| 232 | { |
|---|
| 233 | std::cout<<"Restart"<<std::endl; |
|---|
| 234 | (*itr)->rewind(); |
|---|
| 235 | (*itr)->play(); |
|---|
| 236 | } |
|---|
| 237 | return true; |
|---|
| 238 | } |
|---|
| 239 | else if (ea.getKey()=='L') |
|---|
| 240 | { |
|---|
| 241 | for(ImageStreamList::iterator itr=_imageStreamList.begin(); |
|---|
| 242 | itr!=_imageStreamList.end(); |
|---|
| 243 | ++itr) |
|---|
| 244 | { |
|---|
| 245 | if ( (*itr)->getLoopingMode() == osg::ImageStream::LOOPING) |
|---|
| 246 | { |
|---|
| 247 | std::cout<<"Toggle Looping Off"<<std::endl; |
|---|
| 248 | (*itr)->setLoopingMode( osg::ImageStream::NO_LOOPING ); |
|---|
| 249 | } |
|---|
| 250 | else |
|---|
| 251 | { |
|---|
| 252 | std::cout<<"Toggle Looping On"<<std::endl; |
|---|
| 253 | (*itr)->setLoopingMode( osg::ImageStream::LOOPING ); |
|---|
| 254 | } |
|---|
| 255 | } |
|---|
| 256 | return true; |
|---|
| 257 | } |
|---|
| 258 | return false; |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | default: |
|---|
| 262 | return false; |
|---|
| 263 | } |
|---|
| 264 | return false; |
|---|
| 265 | } |
|---|
| 266 | |
|---|
| 267 | void MovieEventHandler::getUsage(osg::ApplicationUsage& usage) const |
|---|
| 268 | { |
|---|
| 269 | usage.addKeyboardMouseBinding("p","Play/Pause movie"); |
|---|
| 270 | usage.addKeyboardMouseBinding("r","Restart movie"); |
|---|
| 271 | usage.addKeyboardMouseBinding("l","Toggle looping of movie"); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | osg::Geometry* myCreateTexturedQuadGeometry(const osg::Vec3& pos,float width,float height, osg::Image* image, bool useTextureRectangle, bool xyPlane, bool option_flip) |
|---|
| 276 | { |
|---|
| 277 | bool flip = image->getOrigin()==osg::Image::TOP_LEFT; |
|---|
| 278 | if (option_flip) flip = !flip; |
|---|
| 279 | |
|---|
| 280 | if (useTextureRectangle) |
|---|
| 281 | { |
|---|
| 282 | osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos, |
|---|
| 283 | osg::Vec3(width,0.0f,0.0f), |
|---|
| 284 | xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height), |
|---|
| 285 | 0.0f, flip ? image->t() : 0.0, image->s(), flip ? 0.0 : image->t()); |
|---|
| 286 | |
|---|
| 287 | osg::TextureRectangle* texture = new osg::TextureRectangle(image); |
|---|
| 288 | texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); |
|---|
| 289 | texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); |
|---|
| 290 | |
|---|
| 291 | |
|---|
| 292 | pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, |
|---|
| 293 | texture, |
|---|
| 294 | osg::StateAttribute::ON); |
|---|
| 295 | |
|---|
| 296 | return pictureQuad; |
|---|
| 297 | } |
|---|
| 298 | else |
|---|
| 299 | { |
|---|
| 300 | osg::Geometry* pictureQuad = osg::createTexturedQuadGeometry(pos, |
|---|
| 301 | osg::Vec3(width,0.0f,0.0f), |
|---|
| 302 | xyPlane ? osg::Vec3(0.0f,height,0.0f) : osg::Vec3(0.0f,0.0f,height), |
|---|
| 303 | 0.0f, flip ? 1.0f : 0.0f , 1.0f, flip ? 0.0f : 1.0f); |
|---|
| 304 | |
|---|
| 305 | osg::Texture2D* texture = new osg::Texture2D(image); |
|---|
| 306 | texture->setResizeNonPowerOfTwoHint(false); |
|---|
| 307 | texture->setFilter(osg::Texture::MIN_FILTER,osg::Texture::LINEAR); |
|---|
| 308 | texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE); |
|---|
| 309 | texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE); |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | pictureQuad->getOrCreateStateSet()->setTextureAttributeAndModes(0, |
|---|
| 313 | texture, |
|---|
| 314 | osg::StateAttribute::ON); |
|---|
| 315 | |
|---|
| 316 | return pictureQuad; |
|---|
| 317 | } |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | int main(int argc, char** argv) |
|---|
| 321 | { |
|---|
| 322 | |
|---|
| 323 | osg::ArgumentParser arguments(&argc,argv); |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | arguments.getApplicationUsage()->setApplicationName(arguments.getApplicationName()); |
|---|
| 327 | arguments.getApplicationUsage()->setDescription(arguments.getApplicationName()+" example demonstrates the use of ImageStream for rendering movies as textures."); |
|---|
| 328 | arguments.getApplicationUsage()->setCommandLineUsage(arguments.getApplicationName()+" [options] filename ..."); |
|---|
| 329 | arguments.getApplicationUsage()->addCommandLineOption("-h or --help","Display this information"); |
|---|
| 330 | arguments.getApplicationUsage()->addCommandLineOption("--texture2D","Use Texture2D rather than TextureRectangle."); |
|---|
| 331 | arguments.getApplicationUsage()->addCommandLineOption("--shader","Use shaders to post process the video."); |
|---|
| 332 | arguments.getApplicationUsage()->addCommandLineOption("--interactive","Use camera manipulator to allow movement around movie."); |
|---|
| 333 | arguments.getApplicationUsage()->addCommandLineOption("--flip","Flip the movie so top becomes bottom."); |
|---|
| 334 | arguments.getApplicationUsage()->addCommandLineOption("--devices","Print the Video input capability via QuickTime and exit."); |
|---|
| 335 | |
|---|
| 336 | bool useTextureRectangle = true; |
|---|
| 337 | bool useShader = false; |
|---|
| 338 | |
|---|
| 339 | |
|---|
| 340 | osgViewer::Viewer viewer(arguments); |
|---|
| 341 | |
|---|
| 342 | if (arguments.argc()<=1) |
|---|
| 343 | { |
|---|
| 344 | arguments.getApplicationUsage()->write(std::cout,osg::ApplicationUsage::COMMAND_LINE_OPTION); |
|---|
| 345 | return 1; |
|---|
| 346 | } |
|---|
| 347 | |
|---|
| 348 | |
|---|
| 349 | if (arguments.read("-devices") || arguments.read("--devices")) |
|---|
| 350 | { |
|---|
| 351 | |
|---|
| 352 | osgDB::readImageFile("devices.live"); |
|---|
| 353 | return 1; |
|---|
| 354 | } |
|---|
| 355 | |
|---|
| 356 | while (arguments.read("--texture2D")) useTextureRectangle=false; |
|---|
| 357 | while (arguments.read("--shader")) useShader=true; |
|---|
| 358 | |
|---|
| 359 | bool mouseTracking = false; |
|---|
| 360 | while (arguments.read("--mouse")) mouseTracking=true; |
|---|
| 361 | |
|---|
| 362 | |
|---|
| 363 | |
|---|
| 364 | if (arguments.read("-h") || arguments.read("--help")) |
|---|
| 365 | { |
|---|
| 366 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 367 | return 1; |
|---|
| 368 | } |
|---|
| 369 | |
|---|
| 370 | bool fullscreen = !arguments.read("--interactive"); |
|---|
| 371 | bool flip = arguments.read("--flip"); |
|---|
| 372 | |
|---|
| 373 | osg::ref_ptr<osg::Geode> geode = new osg::Geode; |
|---|
| 374 | |
|---|
| 375 | osg::StateSet* stateset = geode->getOrCreateStateSet(); |
|---|
| 376 | stateset->setMode(GL_LIGHTING,osg::StateAttribute::OFF); |
|---|
| 377 | |
|---|
| 378 | if (useShader) |
|---|
| 379 | { |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | static const char *shaderSourceTextureRec = { |
|---|
| 383 | "uniform vec4 cutoff_color;\n" |
|---|
| 384 | "uniform samplerRect movie_texture;\n" |
|---|
| 385 | "void main(void)\n" |
|---|
| 386 | "{\n" |
|---|
| 387 | " vec4 texture_color = textureRect(movie_texture, gl_TexCoord[0].st); \n" |
|---|
| 388 | " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" |
|---|
| 389 | " gl_FragColor = texture_color;\n" |
|---|
| 390 | "}\n" |
|---|
| 391 | }; |
|---|
| 392 | |
|---|
| 393 | static const char *shaderSourceTexture2D = { |
|---|
| 394 | "uniform vec4 cutoff_color;\n" |
|---|
| 395 | "uniform sampler2D movie_texture;\n" |
|---|
| 396 | "void main(void)\n" |
|---|
| 397 | "{\n" |
|---|
| 398 | " vec4 texture_color = texture2D(movie_texture, gl_TexCoord[0].st); \n" |
|---|
| 399 | " if (all(lessThanEqual(texture_color,cutoff_color))) discard; \n" |
|---|
| 400 | " gl_FragColor = texture_color;\n" |
|---|
| 401 | "}\n" |
|---|
| 402 | }; |
|---|
| 403 | |
|---|
| 404 | osg::Program* program = new osg::Program; |
|---|
| 405 | |
|---|
| 406 | program->addShader(new osg::Shader(osg::Shader::FRAGMENT, |
|---|
| 407 | useTextureRectangle ? shaderSourceTextureRec : shaderSourceTexture2D)); |
|---|
| 408 | |
|---|
| 409 | stateset->addUniform(new osg::Uniform("cutoff_color",osg::Vec4(0.1f,0.1f,0.1f,1.0f))); |
|---|
| 410 | stateset->addUniform(new osg::Uniform("movie_texture",0)); |
|---|
| 411 | |
|---|
| 412 | stateset->setAttribute(program); |
|---|
| 413 | |
|---|
| 414 | } |
|---|
| 415 | |
|---|
| 416 | osg::Vec3 pos(0.0f,0.0f,0.0f); |
|---|
| 417 | osg::Vec3 topleft = pos; |
|---|
| 418 | osg::Vec3 bottomright = pos; |
|---|
| 419 | |
|---|
| 420 | bool xyPlane = fullscreen; |
|---|
| 421 | |
|---|
| 422 | for(int i=1;i<arguments.argc();++i) |
|---|
| 423 | { |
|---|
| 424 | if (arguments.isString(i)) |
|---|
| 425 | { |
|---|
| 426 | osg::Image* image = osgDB::readImageFile(arguments[i]); |
|---|
| 427 | osg::ImageStream* imagestream = dynamic_cast<osg::ImageStream*>(image); |
|---|
| 428 | if (imagestream) imagestream->play(); |
|---|
| 429 | |
|---|
| 430 | if (image) |
|---|
| 431 | { |
|---|
| 432 | osg::notify(osg::NOTICE)<<"image->s()"<<image->s()<<" image-t()="<<image->t()<<std::endl; |
|---|
| 433 | |
|---|
| 434 | geode->addDrawable(myCreateTexturedQuadGeometry(pos,image->s(),image->t(),image, useTextureRectangle, xyPlane, flip)); |
|---|
| 435 | |
|---|
| 436 | bottomright = pos + osg::Vec3(static_cast<float>(image->s()),static_cast<float>(image->t()),0.0f); |
|---|
| 437 | |
|---|
| 438 | if (xyPlane) pos.y() += image->t()*1.05f; |
|---|
| 439 | else pos.z() += image->t()*1.05f; |
|---|
| 440 | } |
|---|
| 441 | else |
|---|
| 442 | { |
|---|
| 443 | std::cout<<"Unable to read file "<<arguments[i]<<std::endl; |
|---|
| 444 | } |
|---|
| 445 | } |
|---|
| 446 | } |
|---|
| 447 | |
|---|
| 448 | |
|---|
| 449 | viewer.setSceneData(geode.get()); |
|---|
| 450 | |
|---|
| 451 | if (viewer.getSceneData()==0) |
|---|
| 452 | { |
|---|
| 453 | arguments.getApplicationUsage()->write(std::cout); |
|---|
| 454 | return 1; |
|---|
| 455 | } |
|---|
| 456 | |
|---|
| 457 | |
|---|
| 458 | MovieEventHandler* meh = new MovieEventHandler(); |
|---|
| 459 | meh->setMouseTracking( mouseTracking ); |
|---|
| 460 | meh->set( viewer.getSceneData() ); |
|---|
| 461 | viewer.addEventHandler( meh ); |
|---|
| 462 | |
|---|
| 463 | viewer.addEventHandler( new osgViewer::StatsHandler ); |
|---|
| 464 | viewer.addEventHandler( new osgGA::StateSetManipulator( viewer.getCamera()->getOrCreateStateSet() ) ); |
|---|
| 465 | viewer.addEventHandler( new osgViewer::WindowSizeHandler ); |
|---|
| 466 | |
|---|
| 467 | |
|---|
| 468 | viewer.addEventHandler(new osgViewer::RecordCameraPathHandler); |
|---|
| 469 | |
|---|
| 470 | |
|---|
| 471 | if (arguments.errors()) |
|---|
| 472 | { |
|---|
| 473 | arguments.writeErrorMessages(std::cout); |
|---|
| 474 | return 1; |
|---|
| 475 | } |
|---|
| 476 | |
|---|
| 477 | if (fullscreen) |
|---|
| 478 | { |
|---|
| 479 | viewer.realize(); |
|---|
| 480 | |
|---|
| 481 | viewer.getCamera()->setViewMatrix(osg::Matrix::identity()); |
|---|
| 482 | viewer.getCamera()->setProjectionMatrixAsOrtho2D(topleft.x(),bottomright.x(),topleft.y(),bottomright.y()); |
|---|
| 483 | |
|---|
| 484 | while(!viewer.done()) |
|---|
| 485 | { |
|---|
| 486 | viewer.frame(); |
|---|
| 487 | } |
|---|
| 488 | return 0; |
|---|
| 489 | } |
|---|
| 490 | else |
|---|
| 491 | { |
|---|
| 492 | |
|---|
| 493 | return viewer.run(); |
|---|
| 494 | } |
|---|
| 495 | } |
|---|