Commit 7b352035 authored by Sebastian Eichelbaum's avatar Sebastian Eichelbaum
Browse files

[FIX] transposed matrix caused wrong mv and P matrices being used. This is now...

[FIX] transposed matrix caused wrong mv and P matrices being used. This is now fixed. The click point and vector are correct now.
parent 9c9267c9
...@@ -67,12 +67,12 @@ void WGetMatrixCallback::operator()( osg::Node* node, osg::NodeVisitor* nv ) ...@@ -67,12 +67,12 @@ void WGetMatrixCallback::operator()( osg::Node* node, osg::NodeVisitor* nv )
// property's get() method to avoid locking // property's get() method to avoid locking
if( mvMat != m_currentModelViewMatrix ) if( mvMat != m_currentModelViewMatrix )
{ {
m_modelViewMatrix->set( mvMat ); m_modelViewMatrix->set( transpose( static_cast< WMatrix4d >( mvMat ) ) );
m_currentModelViewMatrix = mvMat; m_currentModelViewMatrix = mvMat;
} }
if( projMat != m_currentProjectionMatrix ) if( projMat != m_currentProjectionMatrix )
{ {
m_projectionMatrix->set( projMat ); m_projectionMatrix->set( transpose( static_cast< WMatrix4d >( projMat ) ) );
m_currentProjectionMatrix = projMat; m_currentProjectionMatrix = projMat;
} }
if( viewportX != m_currentViewportX ) if( viewportX != m_currentViewportX )
......
...@@ -407,6 +407,12 @@ void WMTransferCalc::onClick( WVector2i mousePos ) ...@@ -407,6 +407,12 @@ void WMTransferCalc::onClick( WVector2i mousePos )
0.0, 0.0,
1.0 ); 1.0 );
WVector4d vecInClipSpace( 0.0,
0.0,
1.0,
0.0 );
// get the both matrices inverted // get the both matrices inverted
WMatrix4d projectionMatrixInverted = invert( m_matrixCallback->getProjectionMatrix()->get() ); WMatrix4d projectionMatrixInverted = invert( m_matrixCallback->getProjectionMatrix()->get() );
WMatrix4d modelviewMatrixInverted = invert( m_matrixCallback->getModelViewMatrix()->get() ); WMatrix4d modelviewMatrixInverted = invert( m_matrixCallback->getModelViewMatrix()->get() );
...@@ -416,6 +422,10 @@ void WMTransferCalc::onClick( WVector2i mousePos ) ...@@ -416,6 +422,10 @@ void WMTransferCalc::onClick( WVector2i mousePos )
// get back to model-space // get back to model-space
WVector4d pInObjectSpace = modelviewMatrixInverted * pInWorldSpace; WVector4d pInObjectSpace = modelviewMatrixInverted * pInWorldSpace;
WVector4d vecInWorldSpace = projectionMatrixInverted * vecInClipSpace;
// get back to model-space
WVector4d vecInObjectSpace = modelviewMatrixInverted * vecInWorldSpace;
debugLog() << pInWorldSpace << " --- " << pInObjectSpace; debugLog() << pInWorldSpace << " --- " << pInObjectSpace;
//++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
...@@ -444,8 +454,12 @@ void WMTransferCalc::onClick( WVector2i mousePos ) ...@@ -444,8 +454,12 @@ void WMTransferCalc::onClick( WVector2i mousePos )
// rayGeode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); // rayGeode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
rayGeode->addUpdateCallback( new SafeUpdateCallback( this ) ); rayGeode->addUpdateCallback( new SafeUpdateCallback( this ) );
rayGeode->addDrawable( new osg::ShapeDrawable( new osg::Sphere( getAs3D( pInObjectSpace, true ), 5.0f ) ) ); rayGeode->addDrawable( new osg::ShapeDrawable( new osg::Sphere( getAs3D( pInObjectSpace, true ), 2.5f ) ) );
rayGeode->addDrawable( new osg::ShapeDrawable( new osg::Sphere( getAs3D( pInObjectSpace+vecInObjectSpace, true ), 5.0f ) ) );
m_rootNode->clear(); m_rootNode->clear();
m_rootNode->insert( rayGeode ); m_rootNode->insert( rayGeode );
...@@ -468,7 +482,7 @@ void WMTransferCalc::onClick( WVector2i mousePos ) ...@@ -468,7 +482,7 @@ void WMTransferCalc::onClick( WVector2i mousePos )
// osg::ref_ptr< osg::Geode > rayGeode = new osg::Geode(); // osg::ref_ptr< osg::Geode > rayGeode = new osg::Geode();
// // rayGeode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF ); // // rayGeode->getOrCreateStateSet()->setMode( GL_LIGHTING, osg::StateAttribute::OFF );
// rayGeode->addUpdateCallback( new SafeUpdateCallback( this ) ); // rayGeode->addUpdateCallback( new SafeUpdateCallback( this ) );
// //
// unsigned int seed = time( 0 ); // for thread safe rand_r function // unsigned int seed = time( 0 ); // for thread safe rand_r function
// for( unsigned int n = 0; n < samplesInVicinity; n++ ) // for( unsigned int n = 0; n < samplesInVicinity; n++ )
// { // {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment