【问题标题】:Gaze at SCNNode using SceneKit and CoreMotion使用 SceneKit 和 CoreMotion 凝视 SCNNode
【发布时间】:2015-07-31 12:33:15
【问题描述】:

我正在使用 SceneKit 和 CoreMotion 创建一个虚拟现实应用程序。一切正常,但现在我想编写一个函数,通过计算对象在眼睛空间中的位置来检查用户是否正在查看对象。

我正在使用 SCNSceneRendererDelegate 在我的 ViewController 中委托渲染器功能

func renderer(aRenderer: SCNSceneRenderer, updateAtTime time: NSTimeInterval) {

    var motion = motionManager?.deviceMotion

    if (motion != nil) {
        let currentAttitude = motion!.attitude
        let roll = Float(currentAttitude.roll)
        let pitch = Float(currentAttitude.pitch)
        let yaw = Float(currentAttitude.yaw)

        cameraRollNode.eulerAngles = SCNVector3Make(roll, 0.0, 0.0)
        cameraPitchNode.eulerAngles = SCNVector3Make(0.0, 0.0, pitch)
        cameraYawNode.eulerAngles = SCNVector3Make(0.0, yaw, 0.0)        }
}

我在Android(支持官方Cardboard SDK)中编写了以下代码。

private boolean isLookingAtObject(WorldObject object) {
    float[] initVec = { 0, 0, 0, 1.0f };
    float[] objPositionVec = new float[4];

    // Convert object space to camera space. Use the headView from onNewFrame.
    Matrix.multiplyMM(mModelView, 0, this.getHeadViewMatrix(), 0, object.getModel().getModelMatrix().getFloatValues(), 0);
    Matrix.multiplyMV(objPositionVec, 0, mModelView, 0, initVec, 0);

    float pitch = (float) Math.atan2(objPositionVec[1], -objPositionVec[2]);
    float yaw = (float) Math.atan2(objPositionVec[0], -objPositionVec[2]);

    return Math.abs(pitch) < PITCH_LIMIT && Math.abs(yaw) < YAW_LIMIT;
}

有没有办法使用 CoreMotion 和 SceneKit 计算眼睛空间中的对象

【问题讨论】:

    标签: ios swift scenekit core-motion


    【解决方案1】:

    如果您要查找的只是对象是否在视图中,则无需自己进行任何坐标转换数学运算。只问观点——there's a method for that

    【讨论】:

      猜你喜欢
      • 2018-05-12
      • 2017-11-27
      • 2018-03-28
      • 2016-03-25
      • 2014-12-05
      • 2017-01-18
      • 2017-04-15
      • 2021-05-20
      • 1970-01-01
      相关资源
      最近更新 更多