如何解决将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 举报,一经查实,本站将立刻删除。