2017-10-25 14 views
3

2本指のピンチジェスチャーハンドリングを実装する方法Qt3DCameraのFOV?ズームQt3Dのカメラ

マウス/タッチパッドイベントを処理するカメラコントローラはFirstPersonCameraControllerOrbitCameraControllerです。後者にはzoomLimitというプロパティもありますが、その意味はシーンをズームするために必要なものではありません(キューブマップの内側から、カメラの位置は(0, 0, 0)に固定されています)。私は前者を使います。マウスドラッグとシングルフィンガーのタッチイベントは正しく処理されますが、2本のピンチのようなジェスチャーは処理されません。

は私がQt3DさんCameraと対話する簡単な方法PinchAreaにカスタマイズすることができますか?またはQtクイックのAPIは、この意味では直交する。Qt3DのAPI?

答えて

1

ピンチに関する情報を検索するPinchAreaのpinchUpdatedイベントを使用する:DOC

に係るピンチパラメータは、ピンチの規模、中心及び角度を含むピンチジェスチャー、 に関する情報を提供します。これらの値 は、現在のジェスチャーの開始時からの変更のみを反映しているため、 は ピンチプロパティの最小値と最大値の制限を受けません。これは、任意のカスタムQMLで行うことができます

Camera { 
    id: myCamera 
} 

PinchArea { 
    onPinchUpdated: { 
     myCamera.fieldOfView = pinch.scale*someFactor 
    } 
} 

あなたはそれがピンチとカメラにアクセスすることがあります。

だからあなたのような何かを行うことができるはず。 それはカスタムスクリプトである場合、あなたはalwazs私はPinchAreaMouseAreaの組み合わせになってしまったプロパティとして

property Camera myCamera 
0

をカメラを渡すことができます。

import QtQml 2.2 

import QtQuick 2.9 
import QtQuick.Scene3D 2.0 

import Qt3D.Core 2.9 
import Qt3D.Extras 2.9 
import Qt3D.Render 2.9 
import Qt3D.Input 2.1 
import Qt3D.Logic 2.0 

import PanoEntity 1.0 
import Utility 1.0 

Item { 
    property url panorama 
    onPanoramaChanged: { 
     if (panorama.toString().length !== 0) { 
      if (panoEntity.setPanorama(panorama)) { 
       basicCamera.position = Qt.vector3d(0.0, 0.0, 0.0) 
       basicCamera.upVector = Qt.vector3d(0.0, 0.0, 1.0) 
       basicCamera.viewCenter = panoEntity.pano.dir 
       pinchArea.updateFov(defaultFov) 
      } 
     } 
    } 

    property Image previewImage 

    property real fovMin: 20.0 
    property real defaultFov: 60.0 
    property real fovMax: 90.0 

    property real sensitivity: 1.5 
    property real pinchSensitivity: 0.5 

    Scene3D { 
     id: scene3d 

     anchors.fill: parent 

     aspects: ["render", "input", "logic"] 
     cameraAspectRatioMode: Scene3D.AutomaticAspectRatio // basicCamera.aspectRatio = width/height 
     multisample: true 

     Entity { 
      Camera { 
       id: basicCamera 

       projectionType: CameraLens.PerspectiveProjection 
       nearPlane: 0.1 
       farPlane: 2.0 * Math.SQRT2 
      } 

      RenderSettings { 
       id: renderSettings 

       renderPolicy: scene3d.visible ? RenderSettings.Always : RenderSettings.OnDemand 

       ForwardRenderer { 
        camera: basicCamera 

        clearColor: "transparent" 
       } 
      } 

      InputSettings { 
       id: inputSettings 
      } 

      components: [renderSettings, inputSettings] 

      PanoEntity { 
       id: panoEntity 

       MemoryBarrier { 
        waitFor: MemoryBarrier.All 
       } 
      } 
     } 
    } 
    PinchArea { 
     id: pinchArea 

     anchors.fill: parent 

     function updateFov(newFov) { 
      if (newFov > fovMax) { 
       newFov = fovMax 
      } else if (newFov < fovMin) { 
       newFov = fovMin 
      } 
      var eps = 1.0/60.0 
      if (Math.abs(basicCamera.fieldOfView - newFov) > eps) { 
       basicCamera.fieldOfView = newFov 
       zoomer.fov = newFov 
      } 
     } 

     function updatePinch(pinch) { 
      updateFov(basicCamera.fieldOfView * (1.0 + (pinch.previousScale - pinch.scale) * pinchSensitivity)) 
     } 

     onPinchUpdated: { 
      updatePinch(pinch) 
     } 
     onPinchFinished: { 
      updatePinch(pinch) 
     } 

     MouseArea { 
      anchors.fill: parent 

      propagateComposedEvents: true 

      property point startPoint 

      function updateView(mouse) { 
       basicCamera.pan((startPoint.x - mouse.x) * sensitivity * basicCamera.fieldOfView/width, Qt.vector3d(0.0, 0.0, 1.0)) 
       basicCamera.tilt((mouse.y - startPoint.y) * sensitivity * basicCamera.fieldOfView/height) 
       startPoint = Qt.point(mouse.x, mouse.y) 
      } 

      onPressed: { 
       startPoint = Qt.point(mouse.x, mouse.y) 
      } 
      onPositionChanged: { 
       updateView(mouse) 
      } 
      onReleased: { 
       updateView(mouse) 
      } 
     } 
    } 
    Zoomer { 
     id: zoomer 

     fovMax: parent.fovMax 
     defaultFov: parent.defaultFov 
     fovMin: parent.fovMin 

     anchors.horizontalCenter: parent.horizontalCenter 
     anchors.bottom: parent.bottom 
     anchors.bottomMargin: 45 

     onFovChanged: { 
      pinchArea.updateFov(fov); 
     } 
    } 

    Shortcut { 
     context: Qt.WindowShortcut 
     enabled: scene3d.visible 

     sequence: StandardKey.Save 

     onActivated: { 
      panoEntity.pano.dir = basicCamera.viewCenter 
      panoEntity.pano.up = basicCamera.upVector 
      panoEntity.pano.version = 7 
      if (!panoEntity.updatePanorama()) { 
       console.log("Unable to update panorama %1".arg(panorama)) 
      } else if (previewImage && Utility.fileExists(previewImage.source)) { 
       scene3d.grabToImage(function(grabResult) { 
        if (!grabResult.saveToFile(Utility.toLocalFile(previewImage.source))) { 
         console.log("Unable save preview to file: %1".arg(previewImage.source)) 
        } 
       }, Qt.size(512, 512)) 
      } 
     } 
    } 
} 
関連する問題