简体   繁体   中英

How can I use sensor data to affect the object in SceneKit?

I am implementing an AR app in iOS platform with SceneKit . I wanna my object to rotate followed by mobile rotation. For the mobile rotation side, I found there is a parameter called quaternion under CMAttitude class but I am not sure how can I use this parameter to rotate the object I loaded in the scene. Any ideas?

let motionManager = CMMotionManager()
motionManager.deviceMotionUpdateInterval = 1.0 / 60.0
if motionManager.isDeviceMotionAvailable {
    motionManager.startDeviceMotionUpdates(to: OperationQueue.main, withHandler: { (devMotion, error) -> Void in
        //change the left camera node euler angle in x, y, z axis
        cameraNode.eulerAngles = SCNVector3(
            -Float((devMotion?.attitude.roll)!) - Float(M_PI_2),
            Float((motionManager.deviceMotion?.attitude.yaw)!),
            -Float((motionManager.deviceMotion?.attitude.pitch)!)
        )
    })}

I tried this with Playground app in iPad.

我已经尝试过使用Core Motion,但是我要做的是旋转scnCamera

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM