On 1/19/2011 8:54 AM, Paul Martz wrote:
More info -- This is not an issue. "m * v" is equivalent to "v *
mTranspose".
I had previously written code that indicated this was broke for
vectors, but I recently rewrote the test case:
{
osg::Vec4 v( 1.0, 0.0, 0.0, 1.0 );
osg::Matrix m( osg::Matrix::translate( 3., 5., 0. ) );
osg::Plane p( v );
p.transform( m ); // multiply by inverse transpose
osg::notify( osg::NOTICE ) << p << std::endl;
osg::Matrix mInv = osg::Matrix::inverse( m );
osg::Vec4 vPrime = mInv * v; // multiply by inverse transpose
osg::notify( osg::NOTICE ) << vPrime << std::endl;
}
and I am now getting the same results for both the Plane and the Vec4
transform. So my original code must have been flawed.
Back to the original poster, then... Does this eliminate a need for a
transpose() function in the Matrix class?
I'm not 100% sure. My primary motivation for the transpose() function
was to compute a normal matrix (so it could be passed to glsl as an osg
uniform: osg_NormalViewMatrix). My understanding is that the way to do
that is to transpose the inverse of the view matrix (and take the upper
right 3x3), like so:
static osg::Matrix3 toNormalMatrix( const osg::Matrix& mat )
{
osg::Matrix normVMat = osg::Matrix::orthoNormal(
osg::Matrix::transpose( osg::Matrix::inverse( mat ) ) );
osg::Matrix3 normalViewMatrix3x3( normVMat(0,0), normVMat(0,1),
normVMat(0,2),
normVMat(1,0), normVMat(1,1),
normVMat(1,2),
normVMat(2,0), normVMat(2,1),
normVMat(2,2) );
return normalViewMatrix3x3;
}
Multiplication by this normal matrix wouldn't happen until you were
inside of a vertex shader. If we really wanted to avoid transposing the
matrix, I suppose we could instead use a uniform named
osg_NormalViewMatrixTransposed and the shaders would be responsible for
reversing the multiplication order. It would save some cpu time, but I
feel like the solution is less clean. It would be even more confusing
for the osg_NormalViewMatrixInverse uniform, which would become
osg_NormalViewMatrixInverseTransposed. What do you all think?
Rob
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org