diff --git a/applications/osgconv/OrientationConverter.cpp b/applications/osgconv/OrientationConverter.cpp index 3abd69bb1..74251b6f0 100644 --- a/applications/osgconv/OrientationConverter.cpp +++ b/applications/osgconv/OrientationConverter.cpp @@ -12,6 +12,7 @@ OrientationConverter::OrientationConverter( void ) R.makeIdentity(); T.makeIdentity(); _trans_set = false; + _use_world_frame = false; S.makeIdentity(); } @@ -36,21 +37,36 @@ void OrientationConverter::setScale( const Vec3 &scale ) S = Matrix::scale(scale); } +void OrientationConverter::useWorldFrame( bool worldFrame ) +{ + _use_world_frame = worldFrame; +} Node* OrientationConverter::convert( Node *node ) { // Order of operations here is : - // 1. Translate to world origin (0,0,0) + // 1. If world frame option not set, translate to world origin (0,0,0) // 2. Rotate to new orientation // 3. Scale in new orientation coordinates // 4. If an absolute translation was specified then // - translate to absolute translation in world coordinates - // else - // - translate back to model's original origin. + // else if world frame option not set, + // - translate back to model's original origin. BoundingSphere bs = node->getBound(); - Matrix C = Matrix::translate( -bs.center() ); - if( _trans_set == false ) - T = Matrix::translate( bs.center() ); + Matrix C; + + if (_use_world_frame) + { + C.makeIdentity(); + } + else + { + C = Matrix::translate( -bs.center() ); + + if (_trans_set == false) + T = Matrix::translate( bs.center() ); + } + osg::Group* root = new osg::Group; osg::MatrixTransform* transform = new osg::MatrixTransform; diff --git a/applications/osgconv/OrientationConverter.h b/applications/osgconv/OrientationConverter.h index bf2084034..cbe314c09 100644 --- a/applications/osgconv/OrientationConverter.h +++ b/applications/osgconv/OrientationConverter.h @@ -14,7 +14,8 @@ class OrientationConverter { void setRotation( float degrees, const osg::Vec3 &axis ); void setTranslation( const osg::Vec3 &trans); void setScale( const osg::Vec3 &trans); - + void useWorldFrame( bool worldFrame ); + /** return the root of the updated subgraph as the subgraph * the node passed in my flatten during optimization.*/ osg::Node* convert( osg::Node* node ); @@ -25,6 +26,7 @@ class OrientationConverter { osg::Matrix R, T, S; bool _trans_set; + bool _use_world_frame; }; #endif diff --git a/applications/osgconv/osgconv.cpp b/applications/osgconv/osgconv.cpp index 8402b804a..555ca7874 100644 --- a/applications/osgconv/osgconv.cpp +++ b/applications/osgconv/osgconv.cpp @@ -502,6 +502,9 @@ static void usage( const char *prog, const char *msg ) " where X, Y, and Z represent the coordinates of the\n" " absolute position in world space\n" << std::endl; + osg::notify(osg::NOTICE)<<" --use-world-frame - Perform transformations in the world frame, rather\n" + " than relative to the center of the bounding sphere.\n" + << std::endl; osg::notify(osg::NOTICE)<<" --simplify n - Run simplifier prior to output. Argument must be a" << std::endl <<" normalized value for the resultant percentage" << std::endl <<" reduction." << std::endl @@ -616,6 +619,11 @@ int main( int argc, char **argv ) OrientationConverter oc; bool do_convert = false; + if (arguments.read("--use-world-frame")) + { + oc.useWorldFrame(true); + } + std::string str; while (arguments.read("-O",str)) {