From Ryan Pavlik, "Existing osgconv behavior is to transform the model bounding sphere center to the world origin before performing transformations specified on the command line, and translating back after rotation and scaling unless an alternate translation is specified. This patch adds a setting to the OrientationConverter class in osgconv to disable this extra transformation, which has the effect of applying specified transforms with respect to the input world coordinate system, rather than to the center of the bounding sphere. It also adds a command line argument "--use-world-frame" to enable this behavior. When this command line argument is not passed, behavior is unchanged from before the patch. The usage text has been updated to reflect this additional option, and the comments in OrientationConverter are also updated."

Note from Robert Osfield, tweaked the OrientationConverter.cpp a little to improve readability.
This commit is contained in:
Robert Osfield 2011-05-27 11:22:43 +00:00
parent 6bc1c27fe9
commit 9c7234ac2a
3 changed files with 33 additions and 7 deletions

View File

@ -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;

View File

@ -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

View File

@ -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))
{