From 363d1d9d701087cf0e575b92eaa5f19e8c899806 Mon Sep 17 00:00:00 2001 From: Don BURNS Date: Wed, 12 Dec 2001 05:09:33 +0000 Subject: [PATCH] Added translation and scaling to osgconv --- src/Demos/osgconv/OrientationConverter.cpp | 35 ++++++++++-- src/Demos/osgconv/OrientationConverter.h | 7 ++- src/Demos/osgconv/osgconv.cpp | 64 ++++++++++++++++++++-- 3 files changed, 95 insertions(+), 11 deletions(-) diff --git a/src/Demos/osgconv/OrientationConverter.cpp b/src/Demos/osgconv/OrientationConverter.cpp index 4c2bab608..ff443a1f1 100644 --- a/src/Demos/osgconv/OrientationConverter.cpp +++ b/src/Demos/osgconv/OrientationConverter.cpp @@ -11,22 +11,45 @@ using namespace osg; OrientationConverter::OrientationConverter( void ) { + R.makeIdent(); + T.makeIdent(); + _trans_set = false; + S.makeIdent(); } -void OrientationConverter::setConversion( const Vec3 &from, const Vec3 &to ) +void OrientationConverter::setRotation( const Vec3 &from, const Vec3 &to ) { - Quat q; - Matrix M; + R = Matrix::rotate( from, to ); +} - q.makeRot( from, to ); - q.get( M ); +void OrientationConverter::setTranslation( const Vec3 &trans ) +{ + T = Matrix::trans(trans); + _trans_set = true; +} - _cv.setMatrix( M ); +void OrientationConverter::setScale( const Vec3 &scale ) +{ + S = Matrix::scale(scale); } void OrientationConverter::convert( Node &node ) { + // Order of operations here is : + // 1. 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. + BoundingSphere bs = node.getBound(); + Matrix C = Matrix::trans( Vec3(0,0,0) - bs.center() ); + if( _trans_set == false ) + T = Matrix::trans( bs.center() ); + _cv.setMatrix( C * R * S * T ); + node.accept(_cv); } diff --git a/src/Demos/osgconv/OrientationConverter.h b/src/Demos/osgconv/OrientationConverter.h index 9bed4fb91..7cf5f7405 100644 --- a/src/Demos/osgconv/OrientationConverter.h +++ b/src/Demos/osgconv/OrientationConverter.h @@ -9,7 +9,10 @@ class OrientationConverter { public : OrientationConverter(void); - void setConversion( const osg::Vec3 &from, const osg::Vec3 &to); + void setRotation( const osg::Vec3 &from, + const osg::Vec3 &to ); + void setTranslation( const osg::Vec3 &trans); + void setScale( const osg::Vec3 &trans); void convert( osg::Node &node ); private : @@ -78,6 +81,8 @@ class OrientationConverter { }; ConvertVisitor _cv; + osg::Matrix R, T, S; + bool _trans_set; }; #endif diff --git a/src/Demos/osgconv/osgconv.cpp b/src/Demos/osgconv/osgconv.cpp index 09fd4972e..ab4917b0f 100644 --- a/src/Demos/osgconv/osgconv.cpp +++ b/src/Demos/osgconv/osgconv.cpp @@ -33,7 +33,6 @@ static void usage( const char *prog, const char *msg ) osg::notify(osg::NOTICE)<<" done with -l above, as it automatically expands to the"<