0
我使用SceneKit和CoreMotion創建虛擬現實應用程序。一切工作正常,但現在我想編寫一個函數來檢查用戶是否通過計算對象在眼睛空間中的位置來查看對象。使用SceneKit和CoreMotion凝視SCNNode
我使用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下面的代碼(支持官方紙板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