我在SceneKit中对相机有问题,默认情况下我可以移动,旋转,缩放我的相机这一行:
myView.allowsCameraControl = YES;
但是我的相机可以穿过墙壁和地板(这让我可以看到舞台的下面)。
我的第一个请求:是否可以对摄像机应用约束(位置,旋转)?
我的第二个要求:我想制作一个包含舞台的立方体,并在我的立方体和相机之间进行碰撞检测,但它不起作用......
viewDidLoad的代码:
SCNView *myView = (SCNView *)self.view3D;
myView.scene = [SCNScene sceneNamed:@"art.scnassets/Pointe Marrin 3 def 3 def 2.dae"];
myView.scene.physicsWorld.contactDelegate = self;
myView.scene.physicsWorld.gravity = SCNVector3Make(0, 0, 0);
cubeLimite = [myView.scene.rootNode childNodeWithName:@"Cube" recursively:YES];
camera = [myView.scene.rootNode childNodeWithName:@"Caméra" recursively:YES];
cubeLimite.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeDynamic shape:nil];
cubeLimite.physicsBody.mass = 0;
cubeLimite.categoryBitMask = SCNPhysicsCollisionCategoryDefault;
cubeLimite.physicsBody.collisionBitMask = SCNPhysicsCollisionCategoryAll;
//test camera
CGFloat boxSide = 0.001;
SCNBox *box = [SCNBox boxWithWidth:boxSide
height:boxSide
length:boxSide
chamferRadius:0];
SCNNode *boxNode = [SCNNode nodeWithGeometry:box];
SCNPhysicsShape *shape = [SCNPhysicsShape shapeWithGeometry:boxNode.geometry options:nil];
camera.physicsBody = [SCNPhysicsBody bodyWithType:SCNPhysicsBodyTypeDynamic shape:shape];
camera.physicsBody.mass = 0;
camera.categoryBitMask = SCNPhysicsCollisionCategoryDefault;
camera.physicsBody.collisionBitMask = SCNPhysicsCollisionCategoryAll;
代表代码:
- (void)physicsWorld:(SCNPhysicsWorld *)world
didBeginContact:(SCNPhysicsContact *)contact{
NSLog(@"Contact debut");
}
- (void)physicsWorld:(SCNPhysicsWorld *)world
didUpdateContact:(SCNPhysicsContact *)contact{
NSLog(@"Contact milieu");
}
- (void)physicsWorld:(SCNPhysicsWorld *)world didEndContact:(SCNPhysicsContact *)contact{
NSLog(@"Contact fin");
}
代表: SCNPhysicsContactDelegate 在.h文件中声明
想法? 先谢谢你
答案 0 :(得分:0)
据我所知,在启用allowsCameraControl
时限制默认相机是不可能的。
Rotate SCNCamera node looking at an object around an imaginary sphere的答案概述了一种可能对您有用的方法,具体取决于您需要构建的约束。