微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决将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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?