2

The default Qt3D OrbitCameraController's behavior is: - Left mouse to move camera. - Right mouse to rotate camera.

I need opposite solution, to simply rotate show a product model. C++ code or AxisActionHandler maybe work, but I don't known how to write it. Thanks for help.

Surfsky
  • 86
  • 5

1 Answers1

1

After trying different solutions, I used MouseHandler to finish this task. The core codes is below:

Entity{
  id: root
  property Camera camera;
  MouseDevice {
    id: mouseDevice
  }
  MouseHandler {
    property point _lastPt;   // 鼠标最后的位置
    property real _pan;       // 相机沿y轴旋转角度
    property real _tilt;      // 相机沿x轴旋转角度
    on_PanChanged: root.camera.panAboutViewCenter(_pan);
    on_TiltChanged: root.camera.tiltAboutViewCenter(_tilt);

    sourceDevice: mouseDevice
    onPressed: {_lastPt = Qt.point(mouse.x, mouse.y);}
    onPositionChanged: mouseMove(mouse);
    ...
    function mouseMove(mouse){
        if (mouse.buttons == 1){
            _pan = -(mouse.x - _lastPt.x);
            _tilt = (mouse.y - _lastPt.y);
            _lastPt = Qt.point(mouse.x, mouse.y);
        }
    }
  }
}
Nisse Engström
  • 4,738
  • 23
  • 27
  • 42
Surfsky
  • 86
  • 5
  • I think I have a problem similar to yours, but I can't fully understand your solution (I don't know how to do what you've done in C++). I've posted a question already, see if you can help: https://stackoverflow.com/questions/51422690/qt-how-to-get-mouse-events-on-qt3dwindow – Marcos Saito Jul 19 '18 at 18:36