From f87d09b64d1f3a1bfa034fe5058cf5c53a055367 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 8 Jun 2005 08:33:59 +0000 Subject: [PATCH] From Mike Weiblen, "modified .rot pseudoloader plugin so rotation order actually matches the embedded documentation" --- src/osgPlugins/rot/ReaderWriterROT.cpp | 108 ++++++++++++------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/osgPlugins/rot/ReaderWriterROT.cpp b/src/osgPlugins/rot/ReaderWriterROT.cpp index 969427ef5..b93956273 100644 --- a/src/osgPlugins/rot/ReaderWriterROT.cpp +++ b/src/osgPlugins/rot/ReaderWriterROT.cpp @@ -1,4 +1,4 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2004 Robert Osfield +/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield * * This application is open source and may be redistributed and/or modified * freely and without restriction, both in commericial and non commericial @@ -10,10 +10,10 @@ * */ -/* file: src/osgPlugins/rot/ReaderWriterROT.cpp - * author: Mike Weiblen http://mew.cx/ 2004-07-15 - * copyright: (C) 2004 Michael Weiblen - * license: OpenSceneGraph Public License (OSGPL) +/* file: src/osgPlugins/rot/ReaderWriterROT.cpp + * author: Mike Weiblen http://mew.cx/ 2005-06-06 + * copyright: (C) 2005 Michael Weiblen + * license: OpenSceneGraph Public License (OSGPL) */ #include @@ -39,10 +39,10 @@ * * Usage: .,,.globe * where: - * = an model filename. - * = rotation around X axis [degrees] - * = rotation around Y axis [degrees] - * = rotation around Z axis [degrees] + * = an model filename. + * = rotation around X axis [degrees] + * = rotation around Y axis [degrees] + * = rotation around Z axis [degrees] * * example: osgviewer cow.osg.30,60,-90.rot */ @@ -56,63 +56,63 @@ public: virtual bool acceptsExtension(const std::string& extension) const { - return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); + return osgDB::equalCaseInsensitive( extension, EXTENSION_NAME ); } virtual ReadResult readNode(const std::string& fileName, const osgDB::ReaderWriter::Options* options) const { - std::string ext = osgDB::getLowerCaseFileExtension(fileName); - if( !acceptsExtension(ext) ) - return ReadResult::FILE_NOT_HANDLED; + std::string ext = osgDB::getLowerCaseFileExtension(fileName); + if( !acceptsExtension(ext) ) + return ReadResult::FILE_NOT_HANDLED; - osg::notify(osg::INFO) << "ReaderWriterROT( \"" << fileName << "\" )" << std::endl; + osg::notify(osg::INFO) << "ReaderWriterROT( \"" << fileName << "\" )" << std::endl; - // strip the pseudo-loader extension - std::string tmpName = osgDB::getNameLessExtension( fileName ); + // strip the pseudo-loader extension + std::string tmpName = osgDB::getNameLessExtension( fileName ); - // get the next "extension", which actually contains the pseudo-loader parameters - std::string params = osgDB::getFileExtension( tmpName ); - if( params.empty() ) - { - osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + // get the next "extension", which actually contains the pseudo-loader parameters + std::string params = osgDB::getFileExtension( tmpName ); + if( params.empty() ) + { + osg::notify(osg::WARN) << "Missing parameters for " EXTENSION_NAME " pseudo-loader" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - // strip the "params extension", which must leave a sub-filename. - std::string subFileName = osgDB::getNameLessExtension( tmpName ); - if( subFileName == tmpName ) - { - osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + // strip the "params extension", which must leave a sub-filename. + std::string subFileName = osgDB::getNameLessExtension( tmpName ); + if( subFileName == tmpName ) + { + osg::notify(osg::WARN) << "Missing subfilename for " EXTENSION_NAME " pseudo-loader" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - osg::notify(osg::INFO) << EXTENSION_NAME " params = \"" << params << "\"" << std::endl; + osg::notify(osg::INFO) << EXTENSION_NAME " params = \"" << params << "\"" << std::endl; - int h, p, r; - int count = sscanf( params.c_str(), "%d,%d,%d", &h, &p, &r ); - if( count != 3 ) - { - osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + int rx, ry, rz; + int count = sscanf( params.c_str(), "%d,%d,%d", &rx, &ry, &rz ); + if( count != 3 ) + { + osg::notify(osg::WARN) << "Bad parameters for " EXTENSION_NAME " pseudo-loader: \"" << params << "\"" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - // recursively load the subfile. - osg::Node *node = osgDB::readNodeFile( subFileName, options ); - if( !node ) - { - // propagate the read failure upwards - osg::notify(osg::WARN) << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl; - return ReadResult::FILE_NOT_HANDLED; - } + // recursively load the subfile. + osg::Node *node = osgDB::readNodeFile( subFileName, options ); + if( !node ) + { + // propagate the read failure upwards + osg::notify(osg::WARN) << "Subfile \"" << subFileName << "\" could not be loaded" << std::endl; + return ReadResult::FILE_NOT_HANDLED; + } - osg::MatrixTransform *xform = new osg::MatrixTransform; - xform->setDataVariance( osg::Object::STATIC ); - xform->setMatrix( osg::Matrix::rotate( - osg::DegreesToRadians( static_cast(r) ), osg::Vec3( 0, 1, 0 ), - osg::DegreesToRadians( static_cast(p) ), osg::Vec3( 1, 0, 0 ), - osg::DegreesToRadians( static_cast(h) ), osg::Vec3( 0, 0, 1 ) )); - xform->addChild( node ); - return xform; + osg::MatrixTransform *xform = new osg::MatrixTransform; + xform->setDataVariance( osg::Object::STATIC ); + xform->setMatrix( osg::Matrix::rotate( + osg::DegreesToRadians( static_cast(rx) ), osg::Vec3( 1, 0, 0 ), + osg::DegreesToRadians( static_cast(ry) ), osg::Vec3( 0, 1, 0 ), + osg::DegreesToRadians( static_cast(rz) ), osg::Vec3( 0, 0, 1 ) )); + xform->addChild( node ); + return xform; } };