Browse Source

fix mobile

Nikolay Suslov 4 years ago
parent
commit
b754480c67

+ 5 - 6
public/defaults/proxy/aframe/avatar.js

@@ -370,24 +370,23 @@ this.moveHead = function (rotation) {
 
 }
 
-
-this.updateAvatarRotation = function (rotation) { 
+this.updateAvatarBodyRotation = function (rotation) { 
     
     let myRot = this.rotation.clone();
-    let myHeadRot = this.avatarNode.myHead.rotation.clone();
     this.rotation = [myRot.x, rotation.y, myRot.z];
-    this.avatarNode.myHead.rotation = [rotation.x, myHeadRot.y, rotation.z];
 }
 
-this.followAvatarControl = function (position, rotation) {
 
+this.updateAvatarRotation = function (rotation) { 
+    
     let myRot = this.rotation.clone();
     let myHeadRot = this.avatarNode.myHead.rotation.clone();
     this.rotation = [myRot.x, rotation.y, myRot.z];
     this.avatarNode.myHead.rotation = [rotation.x, myHeadRot.y, rotation.z];
-
 }
 
+
+
 this.setUserAvatar = function(aName){
 
     this.displayName = aName;

+ 1 - 2
public/defaults/proxy/aframe/avatar.vwf.json

@@ -42,9 +42,8 @@
                 "height"
             ]
         },
-        "followAvatarControl": {
+        "updateAvatarBodyRotation":{
             "parameters": [
-                "position",
                 "rotation"
             ]
         },

+ 19 - 2
public/drivers/view/aframe.js

@@ -76,6 +76,7 @@ class AFrameView extends Fabric {
                 this.sixDoFDesktop = !AFRAME.utils.device.isMobile() && !AFRAME.utils.device.isMobileVR() && AFRAME.utils.device.checkHeadsetConnected();
     
                 this.isDesktop = !this.threeDoFMobile && !this.sixDoFMobile && !this.sixDoFDesktop && !_app.config.d3DoF && !_app.config.d6DoF;
+                this.isMobile = AFRAME.utils.device.isMobile() && !AFRAME.utils.device.isMobileVR()
                 //!AFRAME.utils.device.isMobile() && 
             },
     
@@ -675,7 +676,12 @@ class AFrameView extends Fabric {
                 let distance = Math.abs(rotation.y - lastRotation.y);
                 if ( distance > delta) {
                     //console.log("rotation not equal")
+                   if (self.isDesktop) {
+                    self.kernel.callMethod(avatarName, "updateAvatarBodyRotation", [rotation]);
+                   } else {
                     self.kernel.callMethod(avatarName, "updateAvatarRotation", [rotation]);
+                   }
+                    
                 }
             }
             self.nodes[avatarName].selfTickRotation = Object.assign({}, rotation);
@@ -713,8 +719,19 @@ class AFrameView extends Fabric {
 
             // let mouse = el.components["desktop-controls"]._mouse;
             // self.kernel.callMethod(avatarName, "trackMouse",[mouse]);
-            let rotation = (AFRAME.utils.device.isMobile() && self.isDesktop) ? elA.getAttribute('rotation') : el.getAttribute('rotation');
+            var rotation = el.getAttribute('rotation');
+            var headRotation = el.object3D.quaternion;
+
+            if (self.isMobile) {
+                var headWorldQuat = new THREE.Quaternion();
+                elA.object3D.getWorldQuaternion(headWorldQuat);
 
+                rotation = this.getWorldRotation(elA, 'XYZ');
+                headRotation = headWorldQuat;
+            }
+            
+            //let rotation = el.getAttribute('rotation');
+            //((AFRAME.utils.device.isMobile() && !AFRAME.utils.device.isMobileVR()) || self.isDesktop) ? elA.getAttribute('rotation') : el.getAttribute('rotation');
              //let rotation =  el.getAttribute('rotation'); //this.getWorldRotation(el, 'YXZ');
 
 
@@ -744,7 +761,7 @@ class AFrameView extends Fabric {
                      self.kernel.setProperty(avatarName, "rotation", rotation);
                      self.kernel.callMethod(avatarName, "moveVRController",[]);
 
-                     self.kernel.callMethod(avatarID, "moveHead", [el.object3D.quaternion]);
+                     self.kernel.callMethod(avatarID, "moveHead", [headRotation]);
                  }
              }