Commit fa3d8465 authored by Alexander Wiebel's avatar Alexander Wiebel

[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
m_View->setLightingMode( osg::View::HEADLIGHT ); // this is the default anyway
m_pickHandler = osg::ref_ptr<WPickHandler>( new WPickHandler() );
m_View->addEventHandler( m_pickHandler );
m_pickHandler = boost::shared_ptr< WPickHandler >( new WPickHandler() );
m_View->addEventHandler( osg::ref_ptr< WPickHandler >( m_pickHandler.get() ) );
}
catch( ... )
{
......@@ -151,7 +151,7 @@ std::string WGEViewer::getName() const
return m_name;
}
osg::ref_ptr<WPickHandler>WGEViewer::getPickHandler()
boost::shared_ptr< WPickHandler > WGEViewer::getPickHandler()
{
return m_pickHandler;
}
......@@ -160,7 +160,7 @@ public:
*
* \return the pick handler
*/
osg::ref_ptr<WPickHandler>getPickHandler();
boost::shared_ptr< WPickHandler > getPickHandler();
protected:
......@@ -180,9 +180,9 @@ protected:
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:
};
......
......@@ -25,6 +25,8 @@
#include <iostream>
#include <string>
#include <osg/Vec3>
#include "WPickHandler.h"
WPickHandler::~WPickHandler()
......@@ -36,6 +38,11 @@ std::string WPickHandler::getHitResult()
return m_hitResult;
}
wmath::WPosition WPickHandler::getHitPosition()
{
return m_hitPosGlobal;
}
boost::signals2::signal1< void, std::string >* WPickHandler::getPickSignal()
{
return &m_pickSignal;
......@@ -124,6 +131,9 @@ void WPickHandler::pick( osgViewer::View* view, const osgGA::GUIEventAdapter& ea
os << " world coords vertex(" << hitr->getWorldIntersectPoint() << ")" << " normal(" << hitr->getWorldIntersectNormal() << ")"
<< std::endl;
m_hitResult += os.str();
osg::Vec3 globalHit = hitr->getWorldIntersectPoint();
m_hitPosGlobal = wmath::WPosition( globalHit[0], globalHit[1], globalHit[2] );
}
m_pickSignal( getHitResult() );
}
......@@ -44,9 +44,10 @@
#include <osg/Camera>
#include <osg/io_utils>
#include <osg/ShapeDrawable>
#include <osgText/Text>
#include "../math/WPosition.h"
/**
* class to handle events with a pick
*/
......@@ -58,9 +59,19 @@ public:
*/
virtual ~WPickHandler();
/**
* Deals with the events found by the osg.
*/
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 );
/**
* Send a pick signal with the string "unpick"
*/
virtual void unpick();
/**
......@@ -68,6 +79,11 @@ public:
*/
std::string getHitResult();
/**
* Returns the position where the first object was picked.
*/
wmath::WPosition getHitPosition();
/**
* returns the m_pickSignal to for registering to it.
*/
......@@ -75,6 +91,7 @@ public:
protected:
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:
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()
{
// use the m_input "data changed" flag
m_moduleState.add( m_input->getDataChangedCondition() );
WKernel::getRunningKernel()->getGui()->getPickSignal()->connect( boost::bind( &WMPrototypeBoxManipulation::updateGFX, this, _1 ) );
// connect updateGFX with picking
boost::shared_ptr< WGEViewer > viewer = WKernel::getRunningKernel()->getGraphicsEngine()->getViewerByName( "main" );
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
ready();
......@@ -270,15 +272,6 @@ void WMPrototypeBoxManipulation::draw( wmath::WPosition minPos, wmath::WPosition
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 )
{
boost::shared_lock<boost::shared_mutex> slock;
......@@ -287,8 +280,7 @@ void WMPrototypeBoxManipulation::updateGFX( std::string text )
if( text.find( "Object ") != std::string::npos
&& text.find( "\"Box\"" ) != std::string::npos )
{
std::string posText = string_utils::tokenize( text, "()" )[1];
wmath::WPosition newPos = getPosFromText( posText );
wmath::WPosition newPos( m_pickHandler->getHitPosition() );
if( m_isPicked )
{
wmath::WVector3D moveVec = m_pickedPosition - newPos;
......
......@@ -38,6 +38,8 @@
#include "../../math/WVector3D.h"
class WPickHandler;
/**
* Prototype module
*/
......@@ -121,6 +123,8 @@ private:
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_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