From fef731c689d6c2e84231439a78d6414cb3bf3531 Mon Sep 17 00:00:00 2001 From: Don BURNS Date: Sat, 13 Oct 2001 06:22:49 +0000 Subject: [PATCH] checking files in to move development location --- src/Demos/osgconv/Makefile | 4 +- src/Demos/osgconv/OrientationConverter.h | 34 ++++ src/Demos/osgconv/orientationconverter.cpp | 47 ++++++ src/Demos/osgconv/osgconv.cpp | 176 +++++++++++++++------ 4 files changed, 212 insertions(+), 49 deletions(-) create mode 100644 src/Demos/osgconv/OrientationConverter.h create mode 100644 src/Demos/osgconv/orientationconverter.cpp diff --git a/src/Demos/osgconv/Makefile b/src/Demos/osgconv/Makefile index 2145c2f36..982b0a5aa 100644 --- a/src/Demos/osgconv/Makefile +++ b/src/Demos/osgconv/Makefile @@ -2,7 +2,9 @@ include ../../../Make/makedefs C++FILES = \ - osgconv.cpp + osgconv.cpp\ + orientationconverter.cpp + TARGET = ../../../bin/osgconv diff --git a/src/Demos/osgconv/OrientationConverter.h b/src/Demos/osgconv/OrientationConverter.h new file mode 100644 index 000000000..525a2dde7 --- /dev/null +++ b/src/Demos/osgconv/OrientationConverter.h @@ -0,0 +1,34 @@ +#ifndef _ORIENTATION_CONVERTER_H +#define _ORIENTATION_CONVERTER_H + +#include +#include +#include +#include + +class OrientationConverter { + public : + OrientationConverter(void); + void setConversion( const osg::Vec3 &from, const osg::Vec3 &to); + void convert( osg::Node &node ); + + private : + OrientationConverter( const OrientationConverter& ) {} + OrientationConverter& operator = (const OrientationConverter& ) { return *this; } + + osg::Matrix _mat; + + + class ConvertVisitor : public osg::NodeVisitor + { + public : + ConvertVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN){} + + virtual void apply( osg::Node &node ) { traverse( node ); } + virtual void apply( osg::Geode &geode ); + }; + + ConvertVisitor _cv; + +}; +#endif diff --git a/src/Demos/osgconv/orientationconverter.cpp b/src/Demos/osgconv/orientationconverter.cpp new file mode 100644 index 000000000..6dc8d3898 --- /dev/null +++ b/src/Demos/osgconv/orientationconverter.cpp @@ -0,0 +1,47 @@ +#include +#include "OrientationConverter.h" + +using namespace osg; + +OrientationConverter::OrientationConverter( void ) +{ + _mat.makeIdent(); +} + +void OrientationConverter::setConversion( const Vec3 &from, const Vec3 &to ) +{ + // This is the default OpenGL UP vector + Vec3 A( 0, 1, 0 ); + + // if from is not equal to the default, we must first rotate beteen A and from + if( A != from ) + { + ; + } + + // Now do a rotation between A and to + + Quat q; + q.makeRot( A, to ); + q.get( _mat ); +} + + +void OrientationConverter::convert( Node &node ) +{ + _cv.apply( node ); +} + + +void OrientationConverter::ConvertVisitor::apply( Geode &geode ) +{ + int numdrawables = geode.getNumDrawables(); + + for( int i = 0; i < numdrawables; i++ ) + { + Drawable *dbl = geode.getDrawable( i ); + + if( dbl->isSameKindAs + + } +} diff --git a/src/Demos/osgconv/osgconv.cpp b/src/Demos/osgconv/osgconv.cpp index cc49e43f1..7c0743868 100644 --- a/src/Demos/osgconv/osgconv.cpp +++ b/src/Demos/osgconv/osgconv.cpp @@ -1,76 +1,154 @@ +#include #include #include +#include #include #include #include -int main( int argc, char **argv ) +#include "OrientationConverter.h" + +typedef std::vector FileNameList; + +static bool do_convert = false; + + +static void usage( const char *prog, const char *msg ) { + osg::notify(osg::NOTICE)< FileNameList; - FileNameList fileNames; - - for(int i = 1; i < argc; i++ ) + osg::notify(osg::NOTICE)<< + " Format of orientation argument must be the following:\n" + "\n" + " X1,Y1,Z1-X2,Y2,Z2\n" + "\n" + " where X1,Y1,Z1 represent the UP vector in the input\n" + " files and X2,Y2,Z2 represent the UP vector of the output file.\n" + " For example, to convert a model built in a Y-Up coordinate system\n" + " to a model with a Z-up coordinate system, the argument looks like\n" + "\n" + " 0,1,0-0,0,1" + "\n" + << endl; +} + +static bool +parse_args( int argc, char **argv, FileNameList &fileNames, OrientationConverter &oc ) +{ + int nexti; + + for(int i = 1; i < argc; i=nexti ) { + nexti = i+1; if (argv[i][0]=='-') { - switch(argv[i][1]) - { - case('l'): - ++i; - if (iloadLibrary(argv[i]); - } - break; - case('e'): - ++i; - if (icreateLibraryNameForExt(argv[i]); - osgDB::Registry::instance()->loadLibrary(libName); - } - break; - } + for( unsigned int j = 1; j < strlen( argv[i] ); j++ ) + { + switch(argv[i][j]) + { + case('e'): + if (nexticreateLibraryNameForExt(argv[nexti++]); + osgDB::Registry::instance()->loadLibrary(libName); + } + else + { + usage( argv[0], "Extension option requires an argument." ); + return false; + } + break; + + case('l'): + if (nextiloadLibrary(argv[nexti++]); + } + else + { + usage( argv[0], "Library option requires an argument." ); + return false; + } + break; + + case 'o' : + if( nexti < argc ) + { + osg::Vec3 from, to; + if( sscanf( argv[nexti++], "%f,%f,%f-%f,%f,%f", + &from[0], &from[1], &from[2], + &to[0], &to[1], &to[2] ) != 6 ) + { + usage( argv[0], "Orientation argument format incorrect." ); + return false; + } + oc.setConversion( from, to ); + do_convert = true; + } + else + { + usage( argv[0], "Orientation conversion option requires an argument." ); + return false; + } + break; + + default : + std::string a = "Invalide option " ; + a += "'"; + a += argv[i][j] ; + a += "'."; + usage( argv[0], a.c_str() ); + return false; + break; + } + } } else { fileNames.push_back(argv[i]); } - } if (fileNames.empty()) { - osg::notify(osg::NOTICE)<<"No files specfied."<addChild(child); } } + if( do_convert ) + oc.convert(*group); if (group->getNumChildren()==0) { + osg::notify(osg::NOTICE)<<"Error no data loaded."<