zhouenguang před 3 roky
rodič
revize
4bb3683ee5
2 změnil soubory, kde provedl 18 přidání a 13 odebrání
  1. 4 2
      src/ActionsHandler.js
  2. 14 11
      src/RotationEvent.js

+ 4 - 2
src/ActionsHandler.js

@@ -377,11 +377,10 @@ export default class ActionsHandler {
     */
     
     //zeg
-    rotate({type: type, offsetX: offsetX, width: width}) {
+    rotate({type: type, angle: angle}) {
         //camera的position,angle
         //起始和结束的帧
 
-        let angle = offsetX / width * 2 * Math.PI
         let endRotation = util.xverseRotation2Ue4(window.room.sceneManager.cameraComponent.mainCamera.rotation).yaw
         endRotation = (endRotation % 360 + 360) % 360
         
@@ -390,6 +389,9 @@ export default class ActionsHandler {
 
         let efns = Math.round(endRotation/6)
 
+        // if(sfns == efns) return
+        // console.error(sfns, efns)
+
         if(window.currentFrame == null){
             window.currentFrame = efns
         }

+ 14 - 11
src/RotationEvent.js

@@ -45,23 +45,26 @@ export default class RotationEvent {
             const pageY = e.pageY
             const offsetX = pageX - this.touchStartX
             const offsetY = pageY - this.touchStartY
-            const offsetHeight = this._room.options.canvas.offsetHeight
-            const offsetWidth = this._room.options.canvas.offsetWidth
+            const canvasHeight = this._room.options.canvas.offsetHeight
+            const canvasWidth = this._room.options.canvas.offsetWidth
 
-            let angle = offsetX / offsetWidth * 2 * Math.PI
-            // this._room.actionsHandler.rotate({
-            //     type: 'rotate',
-            //     // angle: angle
-            //     pitch: 0,
-            //     yaw: angle
-            // });
+            // offset累计
+            if(!this.offset) this.offset = 0
+            this.offset += offsetX
+
+            // 累计超过6度
+            let angle = Math.round(this.offset / canvasWidth * 2 * Math.PI / (Math.PI/30)) * (Math.PI/30)
+            if(angle < Math.PI/30) return
 
+            // 开始旋转
             this._room.actionsHandler.rotate({
                 type: 'rotate',
-                offsetX: offsetX,
-                width: this._room.options.canvas.offsetWidth
+                angle: angle
             });
 
+            // 重置累计
+            this.offset = 0
+
             this.touchStartX = pageX;
             this.touchStartY = pageY;
         }