问题
I'm playing around with ARKit and SceneKit.
I have a node A - this is the only node that I've added to the rootNode. Node A is allowed to move freely by moving the phone around, except that it's not allowed to leave the screen.
To achieve that (prevent node A from leaving the screen), I can think of the following ways:
- Add a transform constraint to node A: I've tried to do it in the following manner:
[SCNTransformConstraint transformConstraintInWorldSpace:false withBlock:^SCNMatrix4(SCNNode * _Nonnull node, SCNMatrix4 transform) { bool visible = [self.sceneView isNodeInsideFrustum:node withPointOfView:self.cameraNode]; if (visible) { NSLog(@"visible=%d", visible); } return transform; }];
However, I'm stuck as isNodeInsideFrustum always returns false, even when node A is visible.
- Change the field of view of the camera itself, to follow the node so that it doesn't go out of view. This however, I have no clue how to get started.
What I'm looking to do is pretty much the same as this SpriteKit question here - Keeping an object within the screen. Swift SpriteKit
And yes, since this is ARKit, I realise that node A will change it's position when it's dragged by the edge of a screen.
How can I prevent the node from leaving the field of view?
来源:https://stackoverflow.com/questions/48724596/prevent-scnnode-from-going-out-of-the-screen