Can I get the SCNView camera position when using allowsCameraControl?

前端 未结 2 1020
耶瑟儿~
耶瑟儿~ 2021-01-12 15:34

The SCNView documentation says that setting allowsCameraControl to YES does not update the camera node position when the user changes the point of view. Is there any way to

2条回答
  •  死守一世寂寞
    2021-01-12 16:37

    Assuming mySCNView is the SCNView..

    @property (weak, nonatomic) IBOutlet SCNView *mySCNView;
    

    Then you can get the camera position from..

    NSLog(@"Camera position: %f %f %f", _mySCNView.pointOfView.position.x, _mySCNView.pointOfView.position.y, _mySCNView.pointOfView.position.z);
    
    NSLog(@"Camera rotation: %f %f %f %f", _mySCNView.pointOfView.rotation.x, _mySCNView.pointOfView.rotation.y, _mySCNView.pointOfView.rotation.z, _mySCNView.pointOfView.rotation.w);
    
    NSLog(@"Camera orientat: %f %f %f %f", _mySCNView.pointOfView.orientation.x, _mySCNView.pointOfView.orientation.y, _mySCNView.pointOfView.orientation.z,_mySCNView.pointOfView.orientation.w);
    

    In my case, I turned on allowsCameraControl and adjusted the view, noted down the values, and set them at the start of the app. I only needed to set position and orientation, not rotation.

提交回复
热议问题