OSG QT:マウス世界の座標を取得します

このようなオンラインのコードのほとんどは:

1つの          自動matViewMatrix =撮る> getViewMatrix();
2          自動matProjectionMatrix =撮る> getProjectionMatrix();
3          自動wndMatrix =撮る> getViewport() - > computeWindowMatrix();
4          OSG ::マトリックスMVPW = matViewMatrix * matProjectionMatrix * wndMatrix。
5          OSG ::マトリックスinverseMVPW = OSG ::マトリックス::逆(MVPW)。
6          OSG :: Vec3 mouseWorld = OSG :: Vec3(X、Y、0)* inverseMVPW。

開発とQTの組み合わせの間、および場所が間違っていることが判明し、それはマウスの座標原点であるため、トップが角を左に、そして世界のOSG原点座標系を取得するには、そのYマウスの値は、変換を行う必要があり、左下隅です。

このような何か:

1  空隙 GraphicsWinQt :: mouseMoveEvent(QMouseEvent * イベント2  {
 3      setKeyboardModifiers(イベント)。
4       - > getEventQueue() - > mouseMotion(イベント - > X()、イベント - > Y());
5      あれば(nullptr =!m_pMainWnd)
 6      {
 7          X =オートイベント - > X();
8          自動Y = イベント - > Y();
9          INT iWindowHeight = この - > 高さ()。
10        //坐标值转换
11、Y = iWindowHeight - Y。
12          INT Z = 0 13          OSG ::カメラ*カメラ= m_pViewer-> getCamera();
14  
15          オートmatViewMatrix =撮る> getViewMatrix();
16          自動matProjectionMatrix =撮る> getProjectionMatrix();
17          自動wndMatrix =撮る> getViewport() - > computeWindowMatrix();
18          OSG ::マトリックスMVPW = matViewMatrix * matProjectionMatrix * wndMatrix。
19          OSG ::マトリックスinverseMVPW = OSG ::マトリックス::逆(MVPW)。
20         OSG :: Vec3 mouseWorld = OSG :: Vec3(X、Y、0)* inverseMVPW。
21  
22          オートS = QStringLiteral(" 当前位置:" )。
23の          S + = QStringの(" %1、%2%3 " ).arg(mouseWorld.x())引数(mouseWorld.y())引数(mouseWorld.z())。
24          自動pEvent = MessageEventの:: CreateInstanceを(1 )。
25          pEvent-> m_sMsg = S。
26          qApp-> postEvent(m_pMainWnd、pEvent)。
27      }
 28 }

OSGは別のベクトルで乗算左行ベクトルよう

おすすめ

転載: www.cnblogs.com/bingbingzhe/p/12185372.html