查看: 1575|回复: 10

Qt+osg 触控问题

[复制链接]

该用户从未签到

发表于 2014-11-12 12:45:57 | 显示全部楼层 |阅读模式
GLWidget 不支持触控的,改了一下,处理QTouchEvent,但是效果不对,做不到跟MFC的WM_TOUCH一致,求教怎么处理触控???
  1. case QEvent::TouchBegin:
  2.                 case QEvent::TouchUpdate:
  3.                 case QEvent::TouchEnd:
  4.                 {

  5.                         auto e = static_cast<QTouchEvent*>(event);
  6.                         auto pts = e->touchPoints();
  7.                         Q_ASSERT(!pts.empty());
  8.                         osg::ref_ptr<osgGA::GUIEventAdapter> osgEvent;

  9.                         for( int i = 0; i < pts.size(); ++i)
  10.                         {
  11.                                 if(pts[i].state() & Qt::TouchPointPressed)
  12.                                 {
  13.                                         if(!osgEvent) {
  14.                                                 osgEvent = _gw->getEventQueue()->touchBegan(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_BEGAN, pts[i].screenPos().x(), pts[i].screenPos().y());
  15.                                         }
  16.                                         else {
  17.                                                 osgEvent->addTouchPoint(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_BEGAN, pts[i].screenPos().x(), pts[i].screenPos().y());
  18.                                         }
  19.                                 }
  20.                                 else if(pts[i].state() & Qt::TouchPointMoved)
  21.                                 {
  22.                                         if(!osgEvent) {
  23.                                                 osgEvent = _gw->getEventQueue()->touchMoved(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_MOVED, pts[i].screenPos().x(), pts[i].screenPos().y());
  24.                                         }
  25.                                         else {
  26.                                                 osgEvent->addTouchPoint(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_MOVED, pts[i].screenPos().x(), pts[i].screenPos().y());
  27.                                         }
  28.                                 }
  29.                                 else if(pts[i].state() & Qt::TouchPointReleased)
  30.                                 {
  31.                                         // No double tap detection with RAW TOUCH Events, sorry.
  32.                                         if(!osgEvent) {
  33.                                                 osgEvent = _gw->getEventQueue()->touchEnded(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_ENDED, pts[i].screenPos().x(), pts[i].screenPos().y(), 1);
  34.                                         }
  35.                                         else {
  36.                                                 osgEvent->addTouchPoint(pts[i].id(), osgGA::GUIEventAdapter::TOUCH_ENDED, pts[i].screenPos().x(), pts[i].screenPos().y());
  37.                                         }
  38.                                 }
  39.                         }
  40.                 }return true;
复制代码

该用户从未签到

发表于 2017-7-6 14:42:31 | 显示全部楼层
请问楼主这个问题解决了吗

该用户从未签到

发表于 2017-7-6 17:38:31 | 显示全部楼层
在qt中使用qt的多点触控进行处理,不直接使用osg的触控消息,这样应该能解决您的问题

该用户从未签到

发表于 2017-7-6 17:39:15 | 显示全部楼层
GLWidget应该是支持触控的,可能支持持两个点。

该用户从未签到

发表于 2017-7-6 17:40:44 | 显示全部楼层
qt4.6以上支持多点触控

该用户从未签到

发表于 2017-7-8 10:11:08 | 显示全部楼层
我用的win10 支持10点触控  问题是现在怎么把这些触摸点数据转换给osg eventQuene 让他进行处理
我看SXEarth这个程序的多点触控还是很好的 用着也舒服  说明osg还是支持的  

该用户从未签到

发表于 2017-7-8 10:13:54 | 显示全部楼层
osg_student 发表于 2017-7-6 17:38
在qt中使用qt的多点触控进行处理,不直接使用osg的触控消息,这样应该能解决您的问题

Qt支持多点触控 osg也支持多点触控 但是如果不把Qt的触摸信息传递为osg的事件 osg的操作子并不会处理

该用户从未签到

发表于 2017-7-8 10:14:26 | 显示全部楼层
这样传进去好像效果不行吧

该用户从未签到

发表于 2017-7-8 10:20:02 | 显示全部楼层
bool OsgGraphView::viewportEvent(QEvent *event)
{

    // 处理touch事件
    QEvent::Type evType = event->type();



    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();
            qreal currentScaleFactor =
                    QLineF(touchPoint0.pos(), touchPoint1.pos()).length()
                    / QLineF(touchPoint0.startPos(), touchPoint1.startPos()).length();

            if (touchEvent->touchPointStates() & Qt::TouchPointPressed)
            {
                m_pGraphicsWindow->getEventQueue()->touchBegan(touchPoint0.id(),
                                                               osgGA::GUIEventAdapter::TOUCH_BEGAN,
                                                               touchPoint0.pos().x(),touchPoint0.pos().y());
                m_pGraphicsWindow->getEventQueue()->touchBegan(touchPoint1.id(),
                                                               osgGA::GUIEventAdapter::TOUCH_BEGAN,
                                                               touchPoint1.pos().x(),touchPoint1.pos().y());
            }
            else if (touchEvent->touchPointStates() & Qt::TouchPointMoved)
            {
                //                m_pGraphicsWindow->getEventQueue()->touchMoved(touchPoint0.id(),
                //                                                               osgGA::GUIEventAdapter::TOUCH_MOVED,
                //                                                               touchPoint0.pos().x(),touchPoint0.pos().y());
                //                m_pGraphicsWindow->getEventQueue()->touchMoved(touchPoint1.id(),
                //                                                               osgGA::GUIEventAdapter::TOUCH_MOVED,
                //                                                               touchPoint1.pos().x(),touchPoint1.pos().y());
            }
            else if (touchEvent->touchPointStates() & Qt::TouchPointReleased)
            {
                if(currentScaleFactor>1)
                {
                    ZoomIn();  
                }
                else
                {
                    ZoomOut();
                }
            }
        }
        return true;

    }


    return QGraphicsView::viewportEvent(event);
}
我这样是可行的  但这样的效果不是我想要的  我想要的是把这些触控点数据直接传递给osg事件 让他来进行响应

该用户从未签到

发表于 2017-7-10 20:38:05 | 显示全部楼层
ldxcomeon 发表于 2017-7-8 10:20
bool OsgGraphView::viewportEvent(QEvent *event)
{

就在这个函数中写算法,然后调用osgearth操作器的 rotate、zoom等函数就可以了,没必要非得把时间传递给osgearth

该用户从未签到

发表于 2017-7-19 09:58:32 | 显示全部楼层
osg_student 发表于 2017-7-10 20:38
就在这个函数中写算法,然后调用osgearth操作器的 rotate、zoom等函数就可以了,没必要非得把时间传递给o ...

这样是可行的 不知道楼主是否有类似的用的比较好的算法 不想再造轮子  而且轮子还没有oe的好
您需要登录后才可以回帖 登录 | 注册

本版积分规则

OSG中国官方论坛-有您OSG在中国才更好

网站简介:osgChina是国内首个三维相关技术开源社区,旨在为国内更多的技术开发人员提供最前沿的技术资讯,为更多的三维从业者提供一个学习、交流的技术平台。

联系我们

  • 工作时间:09:00--18:00
  • 反馈邮箱:1315785073@qq.com
快速回复 返回顶部 返回列表