xushiting 3 years ago
parent
commit
2952a2b3dd
5 changed files with 55 additions and 20 deletions
  1. 4 0
      src/ActionsHandler.js
  2. 46 16
      src/RotationEvent.js
  3. 1 0
      src/XMaterialComponent.js
  4. 3 3
      src/XSceneManager.js
  5. 1 1
      src/Xverse_Room.js

+ 4 - 0
src/ActionsHandler.js

@@ -410,6 +410,10 @@ export default class ActionsHandler {
             eFrame:efns
             eFrame:efns
         })
         })
         
         
+        if(typeof(window.star_angle) == 'undefined'){
+            return
+        }
+        this.room.sceneManager.materialComponent.initreceveFrames()
         this.room.doRotate()
         this.room.doRotate()
         //window.room.sceneManager.cameraComponent.mainCamera.rotation.y += angle
         //window.room.sceneManager.cameraComponent.mainCamera.rotation.y += angle
         //window.room.sceneManager.cameraComponent.setCameraPose(cameraState)
         //window.room.sceneManager.cameraComponent.setCameraPose(cameraState)

+ 46 - 16
src/RotationEvent.js

@@ -48,8 +48,8 @@ export default class RotationEvent {
             const canvasHeight = this._room.options.canvas.offsetHeight
             const canvasHeight = this._room.options.canvas.offsetHeight
             const canvasWidth = this._room.options.canvas.offsetWidth
             const canvasWidth = this._room.options.canvas.offsetWidth
 
 
-
-            // 旋转中
+            if(window.initFinished){
+                 // 旋转中
             if(this.rotating) return
             if(this.rotating) return
 
 
 
 
@@ -75,6 +75,8 @@ export default class RotationEvent {
                 this.offset = 0
                 this.offset = 0
                 this.rotating = false
                 this.rotating = false
             }, 1000/32)
             }, 1000/32)
+            }
+           
 
 
             this.touchStartX = pageX;
             this.touchStartX = pageX;
             this.touchStartY = pageY;
             this.touchStartY = pageY;
@@ -99,25 +101,53 @@ export default class RotationEvent {
             const pageY = t.pageY
             const pageY = t.pageY
             const offsetX = pageX - this.touchStartX
             const offsetX = pageX - this.touchStartX
             const offsetY = pageY - this.touchStartY
             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 pitch = 2 * offsetY / offsetHeight;
-            let yaw = 2 * offsetX / offsetWidth;
+            let pitch = 2 * offsetY / canvasHeight;
+            let yaw = 2 * offsetX / canvasWidth;
 
 
             pitch > 1 && (pitch = 1);
             pitch > 1 && (pitch = 1);
             yaw > 1 && (yaw = 1);
             yaw > 1 && (yaw = 1);
 /***********************************************************************xst****************************************************************/
 /***********************************************************************xst****************************************************************/
-            // this._room.actionsHandler.rotate({
-            //     pitch: pitch,
-            //     yaw: yaw
-            // });
-
-            let angle = offsetX / offsetWidth * 2 * Math.PI
-            this._room.actionsHandler.rotate({
-                type: 'rotate',
-                angle: angle
-            });
+
+            // if(window.initFinished){
+            //     let angle = offsetX / offsetWidth * 2 * Math.PI
+            //     this._room.actionsHandler.rotate({
+            //         type: 'rotate',
+            //         angle: angle
+            //     });
+            // }
+
+            if(window.initFinished){
+                // 旋转中
+           if(this.rotating) return
+
+
+           // offset累计
+           if(!this.offset) this.offset = 0
+           this.offset += offsetX
+
+           // 累计超过6度
+           let angle = this.offset / (canvasWidth*10) * (2*Math.PI)
+           angle = Math.round(angle / (Math.PI/30)) * (Math.PI/30)
+           if(Math.abs(angle) < Math.PI/30) return
+
+           this.rotating = true
+
+           setTimeout(() => {
+               // 开始旋转
+               this._room.actionsHandler.rotate({
+                   type: 'rotate',
+                   angle: Math.PI/30 * Math.sign(angle)    // angle
+               });
+
+               // 重置累计
+               this.offset = 0
+               this.rotating = false
+           }, 1000/32)
+           }
+
 /********************************************************************************************************************************************/           
 /********************************************************************************************************************************************/           
             
             
             this.touchStartX = pageX;
             this.touchStartX = pageX;

+ 1 - 0
src/XMaterialComponent.js

@@ -277,6 +277,7 @@ export default class XMaterialComponent {
         let stream = new Uint8Array(buffer)
         let stream = new Uint8Array(buffer)
         var o, a;
         var o, a;
         //fov == -1 && (fov = this.yuvInfo.fov);
         //fov == -1 && (fov = this.yuvInfo.fov);
+        
         let fov = this.yuvInfo.fov
         let fov = this.yuvInfo.fov
         if (this._isUpdateYUV == !0) {
         if (this._isUpdateYUV == !0) {
             const s = {
             const s = {

+ 3 - 3
src/XSceneManager.js

@@ -121,9 +121,9 @@ export default class XSceneManager {
         this.scene.clearCachedVertexData(),
         this.scene.clearCachedVertexData(),
         this.scene.cleanCachedTextureBuffer(),
         this.scene.cleanCachedTextureBuffer(),
         // 周恩光加 调试用工具栏
         // 周恩光加 调试用工具栏
-        this.scene.debugLayer.show({
-            embedMode: true,
-        })
+        // this.scene.debugLayer.show({
+        //     embedMode: true,
+        // })
         this.urlTransformer = t.urlTransformer || (s=>Promise.resolve(s)),
         this.urlTransformer = t.urlTransformer || (s=>Promise.resolve(s)),
         t.logger && defaultLog.setLogger(t.logger),
         t.logger && defaultLog.setLogger(t.logger),
         this.gl = e.getContext("webgl2", {
         this.gl = e.getContext("webgl2", {

+ 1 - 1
src/Xverse_Room.js

@@ -150,7 +150,7 @@ export default class Xverse_Room extends EventEmitter {
             return
             return
         }
         }
         let angle = window.star_angle
         let angle = window.star_angle
-        this.sceneManager.materialComponent.initreceveFrames()
+        //this.sceneManager.materialComponent.initreceveFrames()
 
 
         let cameraPostion0 = util.xversePosition2Ue4(this.sceneManager.cameraComponent.mainCamera.position.clone())
         let cameraPostion0 = util.xversePosition2Ue4(this.sceneManager.cameraComponent.mainCamera.position.clone())
         let playerPosition = this.sceneManager.avatarComponent._mainUser.position
         let playerPosition = this.sceneManager.avatarComponent._mainUser.position