List of all members.
Detailed Description
Definition at line 47 of file Draggers.
Constructor & Destructor Documentation
IntersectingDragger::IntersectingDragger |
( |
| ) |
|
IntersectingDragger::~IntersectingDragger |
( |
| ) |
[protected, virtual] |
Member Function Documentation
const osg::Vec4& osgEarth::Util::IntersectingDragger::getColor |
( |
| ) |
const [inline] |
bool IntersectingDragger::getHit |
( |
const osg::Vec3d & |
start, |
|
|
const osg::Vec3d & |
end, |
|
|
osg::Vec3d & |
intersection |
|
) |
| [protected] |
Definition at line 89 of file Draggers.cpp.
{
if (_node.valid())
{
osg::ref_ptr<osgUtil::LineSegmentIntersector> lsi = new osgUtil::LineSegmentIntersector(start,end);
osgUtil::IntersectionVisitor iv(lsi.get());
_node->accept(iv);
if (lsi->containsIntersections())
{
OE_DEBUG << "Got get hit at " << start << " to " << end << std::endl;
intersection = lsi->getIntersections().begin()->getWorldIntersectPoint();
return true;
}
}
OE_DEBUG << "Warning: Couldn't get hit at " << start << " to " << end << std::endl;
return false;
}
osg::Node* osgEarth::Util::IntersectingDragger::getNode |
( |
| ) |
const [inline] |
const osg::Vec4& osgEarth::Util::IntersectingDragger::getPickColor |
( |
| ) |
const [inline] |
float osgEarth::Util::IntersectingDragger::getSize |
( |
| ) |
const [inline] |
Gets the size of the dragger
Definition at line 73 of file Draggers.
bool IntersectingDragger::handle |
( |
const osgManipulator::PointerInfo & |
pi, |
|
|
const osgGA::GUIEventAdapter & |
ea, |
|
|
osgGA::GUIActionAdapter & |
us |
|
) |
| [virtual] |
Handle pick events on dragger and generate TranslateInLine commands.
Definition at line 117 of file Draggers.cpp.
{
switch (ea.getEventType())
{
case (osgGA::GUIEventAdapter::PUSH):
{
osg::NodePath nodePathToRoot;
computeNodePathToRoot(*this,nodePathToRoot);
_localToWorld = osg::computeLocalToWorld(nodePathToRoot);
_worldToLocal.invert( _localToWorld );
osg::Vec3d near, far, hit;
pointer.getNearFarPoints(near, far);
if (getHit(near, far, hit))
{
_startPoint = hit;
osg::ref_ptr<TranslateCommand> cmd = new TranslateCommand();
cmd->setTranslation(osg::Vec3d(0,0,0));
cmd->setStage(osgManipulator::MotionCommand::START);
cmd->setLocalToWorldAndWorldToLocal(_localToWorld, _worldToLocal);
dispatch(*cmd);
cmd = new TranslateCommand();
hit = hit * _worldToLocal;
osg::Vec3d start = getMatrix().getTrans() * _worldToLocal;
osg::Vec3d translation = hit - start;
cmd->setTranslation(translation);
cmd->setStage(osgManipulator::MotionCommand::MOVE);
cmd->setLocalToWorldAndWorldToLocal(_localToWorld, _worldToLocal);
dispatch(*cmd);
setDrawableColor( _pickColor );
aa.requestRedraw();
}
return true;
}
case (osgGA::GUIEventAdapter::DRAG):
{
osg::Vec3d near, far, hit;
pointer.getNearFarPoints(near, far);
if (getHit(near, far, hit))
{
osg::ref_ptr<TranslateCommand> cmd = new TranslateCommand();
hit = hit * _worldToLocal;
osg::Vec3d start = _startPoint * _worldToLocal;
osg::Vec3d translation = hit - start;
cmd->setTranslation(translation);
cmd->setStage(osgManipulator::MotionCommand::MOVE);
cmd->setLocalToWorldAndWorldToLocal(_localToWorld, _worldToLocal);
dispatch(*cmd);
aa.requestRedraw();
}
return true;
}
case (osgGA::GUIEventAdapter::RELEASE):
{
osg::ref_ptr<TranslateCommand> cmd = new TranslateCommand();
cmd->setStage(osgManipulator::MotionCommand::FINISH);
cmd->setLocalToWorldAndWorldToLocal(_localToWorld, _worldToLocal);
dispatch(*cmd);
setDrawableColor(_color);
aa.requestRedraw();
return true;
}
default:
return false;
}
}
bool IntersectingDragger::handle |
( |
const osgGA::GUIEventAdapter & |
ea, |
|
|
osgGA::GUIActionAdapter & |
aa |
|
) |
| [virtual] |
Definition at line 212 of file Draggers.cpp.
{
if (ea.getHandled()) return false;
osgViewer::View* view = dynamic_cast<osgViewer::View*>(&aa);
if (!view) return false;
bool handled = false;
bool activationPermitted = true;
if (_activationModKeyMask!=0 || _activationKeyEvent!=0)
{
_activationPermittedByModKeyMask = (_activationModKeyMask!=0) ?
((ea.getModKeyMask() & _activationModKeyMask)!=0) :
false;
if (_activationKeyEvent!=0)
{
switch (ea.getEventType())
{
case osgGA::GUIEventAdapter::KEYDOWN:
{
if (ea.getKey()==_activationKeyEvent) _activationPermittedByKeyEvent = true;
break;
}
case osgGA::GUIEventAdapter::KEYUP:
{
if (ea.getKey()==_activationKeyEvent) _activationPermittedByKeyEvent = false;
break;
}
default:
break;
}
}
activationPermitted = _activationPermittedByModKeyMask || _activationPermittedByKeyEvent;
}
if (activationPermitted || _draggerActive)
{
switch (ea.getEventType())
{
case osgGA::GUIEventAdapter::PUSH:
{
osgUtil::LineSegmentIntersector::Intersections intersections;
_pointer.reset();
if (view->computeIntersections(ea.getX(),ea.getY(),intersections))
{
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end();
++hitr)
{
_pointer.addIntersection(hitr->nodePath, hitr->getLocalIntersectPoint());
}
for(osgUtil::LineSegmentIntersector::Intersections::iterator hitr = intersections.begin();
hitr != intersections.end();
++hitr)
{
for (osg::NodePath::const_iterator itr = hitr->nodePath.begin();
itr != hitr->nodePath.end();
++itr)
{
osgManipulator::Dragger* dragger = dynamic_cast<osgManipulator::Dragger*>(*itr);
if (dragger)
{
if (dragger==this)
{
osg::Camera *rootCamera = view->getCamera();
osg::NodePath nodePath = _pointer._hitList.front().first;
osg::NodePath::reverse_iterator ritr;
for(ritr = nodePath.rbegin();
ritr != nodePath.rend();
++ritr)
{
osg::Camera* camera = dynamic_cast<osg::Camera*>(*ritr);
if (camera && (camera->getReferenceFrame()!=osg::Transform::RELATIVE_RF || camera->getParents().empty()))
{
rootCamera = camera;
break;
}
}
_pointer.setCamera(rootCamera);
_pointer.setMousePosition(ea.getX(), ea.getY());
dragger->handle(_pointer, ea, aa);
dragger->setDraggerActive(true);
handled = true;
}
}
}
}
}
}
case osgGA::GUIEventAdapter::DRAG:
case osgGA::GUIEventAdapter::RELEASE:
{
if (_draggerActive)
{
_pointer._hitIter = _pointer._hitList.begin();
_pointer.setMousePosition(ea.getX(), ea.getY());
handle(_pointer, ea, aa);
handled = true;
}
break;
}
default:
break;
}
if (_draggerActive && ea.getEventType() == osgGA::GUIEventAdapter::RELEASE)
{
setDraggerActive(false);
_pointer.reset();
}
}
return handled;
}
void osgEarth::Util::IntersectingDragger::setColor |
( |
const osg::Vec4 & |
color | ) |
[inline] |
Set/Get color for dragger.
Definition at line 61 of file Draggers.
void IntersectingDragger::setDrawableColor |
( |
const osg::Vec4f & |
color | ) |
[protected] |
void osgEarth::Util::IntersectingDragger::setNode |
( |
osg::Node * |
node | ) |
[inline] |
void osgEarth::Util::IntersectingDragger::setPickColor |
( |
const osg::Vec4 & |
color | ) |
[inline] |
Set/Get pick color for dragger. Pick color is color of the dragger when picked. It gives a visual feedback to show that the dragger has been picked.
Definition at line 67 of file Draggers.
void osgEarth::Util::IntersectingDragger::setSize |
( |
float |
size | ) |
[inline] |
Sets the size of the dragger
Definition at line 78 of file Draggers.
void IntersectingDragger::setupDefaultGeometry |
( |
| ) |
[virtual] |
Definition at line 71 of file Draggers.cpp.
{
osg::Sphere* shape = new osg::Sphere(osg::Vec3(0,0,0), _size);
osg::Geode* geode = new osg::Geode();
_shapeDrawable = new osg::ShapeDrawable( shape );
geode->addDrawable( _shapeDrawable.get() );
setDrawableColor( _color );
geode->getOrCreateStateSet()->setMode(GL_DEPTH_TEST, osg::StateAttribute::OFF);
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
osg::AutoTransform* at = new osg::AutoTransform;
at->setAutoScaleToScreen( true );
at->addChild( geode );
addChild( at );
}
Member Data Documentation
The documentation for this class was generated from the following files:
- /home/cube/sources/osgearth/src/osgEarthUtil/Draggers
- /home/cube/sources/osgearth/src/osgEarthUtil/Draggers.cpp