|
讲osg嵌入Qt窗口中,QT窗口采用QGraphicsView 需要在qt的触屏事件 转换为osg事件进行处理 代码如下
if(evType==QEvent::TouchBegin || evType == QEvent::TouchUpdate || evType == QEvent::TouchEnd )
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
QList<QTouchEvent::TouchPoint> touchPoints = touchEvent->touchPoints();
if (touchPoints.count() == 2) {
const QTouchEvent::TouchPoint &touchPoint0 = touchPoints.first();
const QTouchEvent::TouchPoint &touchPoint1 = touchPoints.last();
if(touchEvent->touchPointStates() & Qt::TouchPointPressed)
{
m_pGraphicsWindow->getEventQueue()->touchBegan(touchPoint0.id(),osgGA::GUIEventAdapter::TOUCH_BEGAN,
touchPoint0.startPos().x(), touchPoint0.startPos().y());
m_pGraphicsWindow->getEventQueue()->touchBegan(touchPoint1.id(),osgGA::GUIEventAdapter::TOUCH_BEGAN,
touchPoint1.startPos().x(), touchPoint1.startPos().y());
}
if(touchEvent->touchPointStates() & Qt::TouchPointMoved)
{
m_pGraphicsWindow->getEventQueue()->touchEnded(touchPoint0.id(),osgGA::GUIEventAdapter::TOUCH_STATIONERY,
touchPoint0.lastPos().x(), touchPoint0.lastPos().y(),2);
m_pGraphicsWindow->getEventQueue()->touchEnded(touchPoint1.id(),osgGA::GUIEventAdapter::TOUCH_STATIONERY,
touchPoint1.lastPos().x(), touchPoint1.lastPos().y(),2);
}
if (touchEvent->touchPointStates() & Qt::TouchPointReleased) {
m_pGraphicsWindow->getEventQueue()->touchEnded(touchPoint0.id(),osgGA::GUIEventAdapter::TOUCH_ENDED,
touchPoint0.lastPos().x(), touchPoint0.lastPos().y(),2);
m_pGraphicsWindow->getEventQueue()->touchEnded(touchPoint1.id(),osgGA::GUIEventAdapter::TOUCH_ENDED,
touchPoint1.lastPos().x(), touchPoint1.lastPos().y(),2);
//如何转换为OSG的事件
}
}
return true;
}
现在的问题是touchBegan,touchMovede touchEnded 这些个参数到底得如何传才能正确的让osg操作子响应啊 目前使用的是地球操作子 是支持多点触控的
|
|