Updated osgconv to be able to handle orientation swapping.

This commit is contained in:
Don BURNS
2001-10-13 07:24:25 +00:00
parent 49982ac835
commit 79a992ac72
3 changed files with 41 additions and 9 deletions

View File

@@ -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. */

View File

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

View File

@@ -1,29 +1,37 @@
#include <stdio.h>
#include <osg/GeoSet>
#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<GeoSet *>(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;
}
}
}