Commit fa3d8465 authored by Alexander Wiebel's avatar Alexander Wiebel
Browse files

[CHANGE] pickHandler can return the position as WPosition now.

parent 57ffaebd
...@@ -70,8 +70,8 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, i ...@@ -70,8 +70,8 @@ WGEViewer::WGEViewer( std::string name, osg::ref_ptr<WindowData> wdata, int x, i
m_View->setLightingMode( osg::View::HEADLIGHT ); // this is the default anyway m_View->setLightingMode( osg::View::HEADLIGHT ); // this is the default anyway
m_pickHandler = osg::ref_ptr<WPickHandler>( new WPickHandler() ); m_pickHandler = boost::shared_ptr< WPickHandler >( new WPickHandler() );
m_View->addEventHandler( m_pickHandler ); m_View->addEventHandler( osg::ref_ptr< WPickHandler >( m_pickHandler.get() ) );
} }
catch( ... ) catch( ... )
{ {
...@@ -151,7 +151,7 @@ std::string WGEViewer::getName() const ...@@ -151,7 +151,7 @@ std::string WGEViewer::getName() const
return m_name; return m_name;
} }
osg::ref_ptr<WPickHandler>WGEViewer::getPickHandler() boost::shared_ptr< WPickHandler > WGEViewer::getPickHandler()
{ {
return m_pickHandler; return m_pickHandler;
} }
...@@ -160,7 +160,7 @@ public: ...@@ -160,7 +160,7 @@ public:
* *
* \return the pick handler * \return the pick handler
*/ */
osg::ref_ptr<WPickHandler>getPickHandler(); boost::shared_ptr< WPickHandler > getPickHandler();
protected: protected:
...@@ -180,9 +180,9 @@ protected: ...@@ -180,9 +180,9 @@ protected:
WGECamera::ProjectionMode m_projectionMode; WGECamera::ProjectionMode m_projectionMode;
/** /**
* Reference to the pick handler of the viewer. * Pointer to the pick handler of the viewer.
*/ */
osg::ref_ptr<WPickHandler> m_pickHandler; boost::shared_ptr<WPickHandler> m_pickHandler;
private: private:
}; };
......
...@@ -25,6 +25,8 @@ ...@@ -25,6 +25,8 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <osg/Vec3>
#include "WPickHandler.h" #include "WPickHandler.h"
WPickHandler::~WPickHandler() WPickHandler::~WPickHandler()
...@@ -36,6 +38,11 @@ std::string WPickHandler::getHitResult() ...@@ -36,6 +38,11 @@ std::string WPickHandler::getHitResult()
return m_hitResult; return m_hitResult;
} }
wmath::WPosition WPickHandler::getHitPosition()
{
return m_hitPosGlobal;
}
boost::signals2::signal1< void, std::string >* WPickHandler::getPickSignal() boost::signals2::signal1< void, std::string >* WPickHandler::getPickSignal()
{ {
return &m_pickSignal; return &m_pickSignal;
...@@ -124,6 +131,9 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea ...@@ -124,6 +131,9 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
os << " world coords vertex(" << hitr->getWorldIntersectPoint() << ")" << " normal(" << hitr->getWorldIntersectNormal() << ")" os << " world coords vertex(" << hitr->getWorldIntersectPoint() << ")" << " normal(" << hitr->getWorldIntersectNormal() << ")"
<< std::endl; << std::endl;
m_hitResult += os.str(); m_hitResult += os.str();
osg::Vec3 globalHit = hitr->getWorldIntersectPoint();
m_hitPosGlobal = wmath::WPosition( globalHit[0], globalHit[1], globalHit[2] );
} }
m_pickSignal( getHitResult() ); m_pickSignal( getHitResult() );
} }
...@@ -44,9 +44,10 @@ ...@@ -44,9 +44,10 @@
#include <osg/Camera> #include <osg/Camera>
#include <osg/io_utils> #include <osg/io_utils>
#include <osg/ShapeDrawable> #include <osg/ShapeDrawable>
#include <osgText/Text> #include <osgText/Text>
#include "../math/WPosition.h"
/** /**
* class to handle events with a pick * class to handle events with a pick
*/ */
...@@ -58,9 +59,19 @@ public: ...@@ -58,9 +59,19 @@ public:
*/ */
virtual ~WPickHandler(); virtual ~WPickHandler();
/**
* Deals with the events found by the osg.
*/
bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa ); bool handle( const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter& aa );
/**
* Send a pick signal with the pick information as string
*/
virtual void pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea ); virtual void pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea );
/**
* Send a pick signal with the string "unpick"
*/
virtual void unpick(); virtual void unpick();
/** /**
...@@ -68,6 +79,11 @@ public: ...@@ -68,6 +79,11 @@ public:
*/ */
std::string getHitResult(); std::string getHitResult();
/**
* Returns the position where the first object was picked.
*/
wmath::WPosition getHitPosition();
/** /**
* returns the m_pickSignal to for registering to it. * returns the m_pickSignal to for registering to it.
*/ */
...@@ -75,6 +91,7 @@ public: ...@@ -75,6 +91,7 @@ public:
protected: protected:
std::string m_hitResult; //!< Textual representation of the result of a pick. std::string m_hitResult; //!< Textual representation of the result of a pick.
wmath::WPosition m_hitPosGlobal; //!< Global coordinates of the first hit of the pick.
private: private:
boost::signals2::signal1<void, std::string > m_pickSignal; //!< One can register to this signal to receive pick events. boost::signals2::signal1<void, std::string > m_pickSignal; //!< One can register to this signal to receive pick events.
......
...@@ -86,11 +86,13 @@ void WMPrototypeBoxManipulation::moduleMain() ...@@ -86,11 +86,13 @@ void WMPrototypeBoxManipulation::moduleMain()
{ {
// use the m_input "data changed" flag // use the m_input "data changed" flag
m_moduleState.add( m_input->getDataChangedCondition() ); m_moduleState.add( m_input->getDataChangedCondition() );
WKernel::getRunningKernel()->getGui()->getPickSignal()->connect( boost::bind( &WMPrototypeBoxManipulation::updateGFX, this, _1 ) );
// connect updateGFX with picking // connect updateGFX with picking
boost::shared_ptr< WGEViewer > viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" ); boost::shared_ptr< WGEViewer > viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" );
assert( viewer ); assert( viewer );
viewer->getPickHandler()->getPickSignal()->connect( boost::bind( &WMPrototypeBoxManipulation::updateGFX, this, _1 ) ); m_pickHandler = viewer->getPickHandler();
m_pickHandler->getPickSignal()->connect( boost::bind( &WMPrototypeBoxManipulation::updateGFX, this, _1 ) );
// signal ready state // signal ready state
ready(); ready();
...@@ -270,15 +272,6 @@ void WMPrototypeBoxManipulation::draw( wmath::WPosition minPos, wmath::WPosition ...@@ -270,15 +272,6 @@ void WMPrototypeBoxManipulation::draw( wmath::WPosition minPos, wmath::WPosition
debugLog() << "Intial draw " << std::endl; debugLog() << "Intial draw " << std::endl;
} }
wmath::WPosition getPosFromText( std::string posText )
{
std::vector< std::string > coordText = string_utils::tokenize( posText );
double x = boost::lexical_cast< double >( coordText[0] );
double y = boost::lexical_cast< double >( coordText[1] );
double z = boost::lexical_cast< double >( coordText[2] );
return wmath::WPosition( x, y, z );
}
void WMPrototypeBoxManipulation::updateGFX( std::string text ) void WMPrototypeBoxManipulation::updateGFX( std::string text )
{ {
boost::shared_lock<boost::shared_mutex> slock; boost::shared_lock<boost::shared_mutex> slock;
...@@ -287,8 +280,7 @@ void WMPrototypeBoxManipulation::updateGFX( std::string text ) ...@@ -287,8 +280,7 @@ void WMPrototypeBoxManipulation::updateGFX( std::string text )
if( text.find( "Object ") != std::string::npos if( text.find( "Object ") != std::string::npos
&& text.find( "\"Box\"" ) != std::string::npos ) && text.find( "\"Box\"" ) != std::string::npos )
{ {
std::string posText = string_utils::tokenize( text, "()" )[1]; wmath::WPosition newPos( m_pickHandler->getHitPosition() );
wmath::WPosition newPos = getPosFromText( posText );
if( m_isPicked ) if( m_isPicked )
{ {
wmath::WVector3D moveVec = m_pickedPosition - newPos; wmath::WVector3D moveVec = m_pickedPosition - newPos;
......
...@@ -38,6 +38,8 @@ ...@@ -38,6 +38,8 @@
#include "../../math/WVector3D.h" #include "../../math/WVector3D.h"
class WPickHandler;
/** /**
* Prototype module * Prototype module
*/ */
...@@ -121,6 +123,8 @@ private: ...@@ -121,6 +123,8 @@ private:
wmath::WPosition m_pickedPosition; //!< Caches the old picked position to a allow for cmoparison wmath::WPosition m_pickedPosition; //!< Caches the old picked position to a allow for cmoparison
wmath::WPosition m_minPos; //!< The minimum position of the box wmath::WPosition m_minPos; //!< The minimum position of the box
wmath::WPosition m_maxPos; //!< The maximum position of the box wmath::WPosition m_maxPos; //!< The maximum position of the box
boost::shared_ptr< WPickHandler > m_pickHandler; //!< A pointer to the pick handler used to get gui events for moving the box.
}; };
/** /**
......
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