diff --git a/applications/osgconv/OrientationConverter.cpp b/applications/osgconv/OrientationConverter.cpp index 9bdc5d160..d52c410ab 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,35 @@ 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 ) + 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 1f9923541..ffa9d3763 100644 --- a/applications/osgconv/OrientationConverter.h +++ b/applications/osgconv/OrientationConverter.h @@ -14,6 +14,7 @@ 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.*/ @@ -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 df46fd552..c9ec286c2 100644 --- a/applications/osgconv/osgconv.cpp +++ b/applications/osgconv/osgconv.cpp @@ -478,6 +478,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 @@ -591,6 +594,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)) {