Fixed TransformFunctor code so that it now uses the inverse of the

transformation matrix to transform the normal.
This commit is contained in:
Robert Osfield
2001-10-14 14:23:47 +00:00
parent 6bb865af25
commit 45eefec3f0
2 changed files with 17 additions and 18 deletions

View File

@@ -9,10 +9,14 @@ class TransformFunctor : public osg::Drawable::AttributeFunctor
public:
osg::Matrix _m;
osg::Matrix _im;
TransformFunctor(const osg::Matrix& m):
AttributeFunctor(osg::Drawable::COORDS|osg::Drawable::NORMALS),
_m(m) {}
AttributeFunctor(osg::Drawable::COORDS|osg::Drawable::NORMALS)
{
_m = m;
_im.invert(_m);
}
virtual ~TransformFunctor() {}
@@ -30,16 +34,8 @@ class TransformFunctor : public osg::Drawable::AttributeFunctor
{
for (osg::Vec3* itr=begin;itr<end;++itr)
{
// note post mult rather than pre mult of value.
// Yep, I noted that post mult doesn't work.
// All the normals are upside down or facing the
// wrong way
// -don
//(*itr) = osg::Matrix::transform3x3(_m,(*itr));
//(*itr).normalize();
(*itr) = (*itr) * _m;
// note post mult by inverse for normals.
(*itr) = osg::Matrix::transform3x3(_im,(*itr));
(*itr).normalize();
}
return true;
@@ -69,7 +65,7 @@ void OrientationConverter::setConversion( const Vec3 &from, const Vec3 &to )
void OrientationConverter::convert( Node &node )
{
_cv.apply( node );
node.accept(_cv);
}

View File

@@ -23,14 +23,17 @@
class TransformFunctor : public osg::Drawable::AttributeFunctor
{
public:
osg::Matrix _m;
osg::Matrix _im;
TransformFunctor(const osg::Matrix& m):
AttributeFunctor(osg::Drawable::COORDS|osg::Drawable::NORMALS),
_m(m) {}
AttributeFunctor(osg::Drawable::COORDS|osg::Drawable::NORMALS)
{
_m = m;
_im.invert(_m);
}
virtual ~TransformFunctor() {}
@@ -48,8 +51,8 @@ class TransformFunctor : public osg::Drawable::AttributeFunctor
{
for (osg::Vec3* itr=begin;itr<end;++itr)
{
// note post mult rather than pre mult of value.
(*itr) = osg::Matrix::transform3x3(_m,(*itr));
// note post mult by inverse for normals.
(*itr) = osg::Matrix::transform3x3(_im,(*itr));
(*itr).normalize();
}
return true;