将CoreMotion数据从iOS传递到THREE.js 360英寸全景视图

问题描述

我正在尝试在iOS应用程序内部使用由THREE.js构建的等矩形360英寸全景查看器。全景图将通过WKWebView中的URL加载到应用程序中,而iOS应用程序将控制角度由于某些限制,我决定使用iOS本机运动数据将其传递到THREE.js坐标中。

我的Swift代码使用motionManager.startDeviceMotionUpdates获取运动数据,如下所示:

self.motionManager.startDeviceMotionUpdates(using: .xArbitraryZVertical,to: queue,withHandler: {
  [weak self] (data,error) in
  guard let data = data,error == nil else {return}                                                            
     let rotationMatrix = data.attitude.rotationMatrix
     var userheading = .pi - atan2(rotationMatrix.m32,rotationMatrix.m31)
     userheading += .pi/2
                                                        
     // from Apple's docs: Get the attitude relative to the magnetic north reference frame.
     let roll = data.attitude.roll
     let pitch = data.attitude.pitch
     let yaw = data.attitude.yaw
     /* values examples
       userheading = 5.480206519063177 
       roll = 0.011097616452213759
       pitch = 0.010663498453945656
       yaw -0.0023959391947512084
     */
 //etc.

我的THREE.js全景查看器实现在update()内有此代码

 function update(){
    var coords = Cam.coords;
    var distX = coords.latLon.current.x - coords.latLon.delta.x;
    var distY = coords.latLon.current.y - coords.latLon.delta.y;
    coords.latLon.delta.x += distX/7;
    coords.latLon.delta.y += distY/7;

    coords.phi = THREE.Math.degToRad( 90 - coords.latLon.delta.x );
    coords.theta = THREE.Math.degToRad( coords.latLon.delta.y );

    coords.target.x = 500 * Math.sin( coords.phi ) * Math.cos( coords.theta );
    coords.target.y = 500 * Math.cos( coords.phi );
    coords.target.z = 500 * Math.sin( coords.phi ) * Math.sin( coords.theta );
    Cam.camera.lookAt( coords.target );
    /* values examples
     x = 480.0568721331066 
     y = 13.96081936178438 
     z = -139.10605680747963 
     phi = 1.5428710587629875 
     theta = 6.001140100057258
    */
    renderer.render( Cam.scene,Cam.camera );
 }

我试图了解如何正确地将这些数据从iOS CoreMotion motionManager映射到THREE.js x / y / z和phi / theta。

我确实尝试使用DeviceOrientationControls.js(请参阅link),但在应用程序中无法使用。我认为WKWeebView可能不支持运动功能

需要帮助才能将iOS数据从CoreMotion正确映射到THREE.js

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...