/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield * * This software is open source and may be redistributed and/or modified under * the terms of the GNU General Public License (GPL) version 2.0. * The full license is in LICENSE.txt file included with this distribution,. * * This software is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * include LICENSE.txt for more details. */ #include #include #include #include #include #include #include #include using namespace osgPresentation; PickEventHandler::PickEventHandler(osgPresentation::Operation operation, const JumpData& jumpData): _operation(operation), _jumpData(jumpData), _drawablesOnPush() { OSG_INFO<<"PickEventHandler::PickEventHandler(operation="< " << cloned_ea->getX() << "/" <getY() << std::endl; SlideEventHandler::instance()->forwardEventToDevices(cloned_ea.get()); } else if ((_operation == FORWARD_TOUCH_EVENT) && ea.isMultiTouchEvent()) { osg::ref_ptr cloned_ea = osg::clone(&ea); cloned_ea->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS); osgGA::GUIEventAdapter::TouchData* touch_data = cloned_ea->getTouchData(); // reproject touch-points const osg::BoundingBox bb(hitr->drawable->getBoundingBox()); osg::Camera* camera = viewer->getCamera(); osg::Matrix matrix = osg::computeLocalToWorld(hitr->nodePath, false) * camera->getViewMatrix() * camera->getProjectionMatrix(); matrix.postMult(camera->getViewport()->computeWindowMatrix()); osg::Matrixd inverse; inverse.invert(matrix); // transform touch-points into local coord-system unsigned int j(0); for(osgGA::GUIEventAdapter::TouchData::iterator i = touch_data->begin(); i != touch_data->end(); ++i, ++j) { osg::Vec3 local = osg::Vec3(i->x, i->y, 0) * inverse; // std::cout << local << " hit: " << hitr->localIntersectionPoint << std::endl; local.x() = (local.x() - bb.xMin()) / (bb.xMax() - bb.xMin()); local.z() = (local.z() - bb.zMin()) / (bb.zMax() - bb.zMin()); local.x() = (ea.getXmin() + local.x() * (ea.getXmax() - ea.getXmin())); local.z() = (ea.getYmin() + local.z() * (ea.getYmax() - ea.getYmin())); // std::cout << ea.getX() << "/" << ea.getY() << " -- " << i->x << " " << i->y << " -> " << local.x() <<"/" << local.z() << std::endl; i->x = local.x(); i->y = 1 + local.z(); // no idea why I have to add 1 to get y in the range [0..1] } // std::cout << transformed_x << "/" << transformed_x << " -> " << cloned_ea->getX() << "/" <getY() << std::endl; SlideEventHandler::instance()->forwardEventToDevices(cloned_ea.get()); } else { if (ea.getEventType()==osgGA::GUIEventAdapter::PUSH) { _drawablesOnPush.insert( hitr->drawable.get() ); } else if (ea.getEventType()==osgGA::GUIEventAdapter::MOVE) { OSG_INFO<<"Tooltip..."<drawable.get()) != _drawablesOnPush.end()) doOperation(); return true; } } } } break; } case(osgGA::GUIEventAdapter::KEYDOWN): { //OSG_NOTICE<<"PickEventHandler KEYDOWN "<<(char)ea.getKey()<className()<dispatchEvent(_keyPos); break; } case(osgPresentation::JUMP): { OSG_INFO<<"Requires jump "<