Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用于增强现实的iOS设备姿态_Javascript_Ios_Swift_Three.js_Augmented Reality - Fatal编程技术网

Javascript 用于增强现实的iOS设备姿态

Javascript 用于增强现实的iOS设备姿态,javascript,ios,swift,three.js,augmented-reality,Javascript,Ios,Swift,Three.js,Augmented Reality,我想使用swift跟踪iPhone的设备运动,然后将其交给WebView,相应地旋转一个THREE.js。 (使用THREE.js代替OpenGL进行渲染的原因是为了与我们的网站兼容。) 设备运动的跟踪目前在swift中使用 let motionManager = CMMotionManager() motionManager.accelerometerUpdateInterval = 1 motionManager.gyroUpdateInterval = 1 motionManager.de

我想使用swift跟踪iPhone的设备运动,然后将其交给WebView,相应地旋转一个THREE.js。 (使用THREE.js代替OpenGL进行渲染的原因是为了与我们的网站兼容。)

设备运动的跟踪目前在swift中使用

let motionManager = CMMotionManager()
motionManager.accelerometerUpdateInterval = 1
motionManager.gyroUpdateInterval = 1
motionManager.deviceMotionUpdateInterval = 1/60
motionManager.showsDeviceMovementDisplay = true;

motionManager.startDeviceMotionUpdatesToQueue(NSOperationQueue.currentQueue()!) {
    (motionData: CMDeviceMotion?, NSError) -> Void in
    self.outputData(motionData!.attitude.quaternion.x, motionData!.attitude.quaternion.y, motionData!.attitude.quaternion.z, motionData!.attitude.quaternion.w)

    if(NSError != nil) {
        print("\(NSError)")
    }
}
outputData函数只是将四个参数交给THREE.js,在THREE.js中执行以下代码:

camera.quaternion.set(x, y, z, w);
不幸的是,它根本不起作用

我知道,当手机放在桌子上而不是放在用户面前时,会出现90°的旋转缺失,但这将是下一步

为简单起见,该应用程序目前仅锁定为纵向模式


你知道如何将iOS Pastive.quaternion中的数据转换为THREE.js(或任何其他基于webGL/OpenGL的引擎)可以使用的方式吗?

中的源代码可能会有所帮助。在使用此类之前,我已经对其进行了研究并使其正常工作,但我需要通过本机iOS使Pastive正常工作,而且看起来,通过window.addEventListener('deviceorientation')接收的值与motionData.attitude中的值不同