diff --git a/include/osg/GeoSet b/include/osg/GeoSet index 0b0b91f23..261ad686f 100644 --- a/include/osg/GeoSet +++ b/include/osg/GeoSet @@ -163,7 +163,9 @@ class SG_EXPORT GeoSet : public Drawable void computeNumVerts(); /** get the number of coords required by the defined primitives. */ - inline const int getNumCoords() const { return _numcoords; } + // inline const int getNumCoords() const + inline const int getNumCoords() + { if( _numcoords == 0 ) computeNumVerts(); return _numcoords; } /** get a pointer to Vec3 coord array. */ inline Vec3* getCoords() { return _coords; } /** get a const pointer to Vec3 coord array. */ diff --git a/src/Demos/osgconv/OrientationConverter.h b/src/Demos/osgconv/OrientationConverter.h index 525a2dde7..cd2aafef5 100644 --- a/src/Demos/osgconv/OrientationConverter.h +++ b/src/Demos/osgconv/OrientationConverter.h @@ -16,16 +16,23 @@ class OrientationConverter { OrientationConverter( const OrientationConverter& ) {} OrientationConverter& operator = (const OrientationConverter& ) { return *this; } - osg::Matrix _mat; class ConvertVisitor : public osg::NodeVisitor { public : - ConvertVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN){} + ConvertVisitor() : osg::NodeVisitor(TRAVERSE_ALL_CHILDREN) + { + _mat.makeIdent(); + } + + void setMatrix( osg::Matrix mat ) { _mat = mat; } virtual void apply( osg::Node &node ) { traverse( node ); } virtual void apply( osg::Geode &geode ); + + private : + osg::Matrix _mat; }; ConvertVisitor _cv; diff --git a/src/Demos/osgconv/orientationconverter.cpp b/src/Demos/osgconv/orientationconverter.cpp index 6dc8d3898..df44660a0 100644 --- a/src/Demos/osgconv/orientationconverter.cpp +++ b/src/Demos/osgconv/orientationconverter.cpp @@ -1,29 +1,37 @@ #include +#include #include "OrientationConverter.h" using namespace osg; OrientationConverter::OrientationConverter( void ) { - _mat.makeIdent(); + //_mat.makeIdent(); } void OrientationConverter::setConversion( const Vec3 &from, const Vec3 &to ) { + Quat q; + Matrix mat; // 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 ) { - ; + Vec3 aa = A; + q.makeRot( A, from ); + q.get( mat ); + + A = aa * mat; } // Now do a rotation between A and to - Quat q; q.makeRot( A, to ); - q.get( _mat ); + q.get( mat ); + _cv.setMatrix( mat ); + } @@ -37,11 +45,26 @@ void OrientationConverter::ConvertVisitor::apply( Geode &geode ) { int numdrawables = geode.getNumDrawables(); + // We assume all Drawables are GeoSets ?!!? for( int i = 0; i < numdrawables; i++ ) { - Drawable *dbl = geode.getDrawable( i ); + GeoSet *gset = dynamic_cast(geode.getDrawable(i)); + int numcoords = gset->getNumCoords(); + Vec3 *vertex = gset->getCoords(); - if( dbl->isSameKindAs + for( int i = 0; i < numcoords; i++ ) + { + Vec3 vv = vertex[i]; + vertex[i] = vv * _mat; + } + + int numnormals = gset->getNumNormals(); + Vec3 *normals = gset->getNormals(); + for( int i = 0; i < numnormals; i++ ) + { + Vec3 vv = normals[i]; + normals[i] = vv * _mat; + } } }