【发布时间】:2016-01-12 16:27:35
【问题描述】:
我正在尝试使用 SceneKit 检测给定区域内的触摸。使用一个几何体执行此操作相当简单(您只需在场景视图上执行命中测试)但是,我有一个由SCNNodes (SCNVector3s) 数组定义的自定义区域。
我像这样创建我的自定义区域:
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (!self.isMakingLine) {
[super touchesBegan:touches withEvent:event];
} else {
self.vectors = [[NSMutableArray alloc] init];
NSArray <SCNHitTestResult *> *res = [self.sceneView hitTest:[[touches anyObject] locationInView:self.sceneView] options:@{SCNHitTestFirstFoundOnlyKey : @YES}];
if (res.count) {
SCNHitTestResult *result = res.lastObject;
if (result.node == self.sphereNode) {
SCNNode *n = [SCNNode nodeWithGeometry:[SCNBox boxWithWidth:0.01 height:0.01 length:0.01 chamferRadius:0]];
n.geometry.firstMaterial.diffuse.contents = [UIColor greenColor];
n.position = result.localCoordinates;
[self.sphereNode addChildNode:n];
[self.vectors addObject:n];
}
}
}
}
- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (!self.isMakingLine) {
[super touchesMoved:touches withEvent:event];
} else {
NSArray <SCNHitTestResult *> *res = [self.sceneView hitTest:[[touches anyObject] locationInView:self.sceneView] options:@{SCNHitTestFirstFoundOnlyKey : @YES}];
if (res.count) {
SCNHitTestResult *result = res.lastObject;
if (result.node == self.sphereNode) {
SCNNode *n = [SCNNode nodeWithGeometry:[SCNBox boxWithWidth:0.01 height:0.01 length:0.01 chamferRadius:0]];
n.geometry.firstMaterial.diffuse.contents = [UIColor greenColor];
n.position = result.localCoordinates;
[self.sphereNode addChildNode:n];
[self.vectors addObject:n];
}
}
}
}
- (void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
if (!self.isMakingLine) {
[super touchesEnded:touches withEvent:event];
} else {
NSArray <SCNHitTestResult *> *res = [self.sceneView hitTest:[[touches anyObject] locationInView:self.sceneView] options:@{SCNHitTestFirstFoundOnlyKey : @YES}];
if (res.count) {
SCNHitTestResult *result = res.lastObject;
if (result.node == self.sphereNode) {
SCNNode *n = [SCNNode nodeWithGeometry:[SCNBox boxWithWidth:0.01 height:0.01 length:0.01 chamferRadius:0]];
n.geometry.firstMaterial.diffuse.contents = [UIColor greenColor];
n.position = result.localCoordinates;
[self.sphereNode addChildNode:n];
[self.vectors addObject:n];
self.isMakingLine = NO;
}
}
}
}
那么鉴于我的SCNBoxes 数组,我如何检测其他点是否落在它们中间?
【问题讨论】:
标签: objective-c 3d scenekit