ノード (以下のコード) を選択し、それを「テーブル」上でドラッグしたいと思います。選択するためのコードは簡単ですが、選択したノードをドラッグする方法がわかりません。私の試みは以下のとおりです。
このコードの一部は、SceneKit を使用した 3D グラフィックスからのものです。
- (void)handleTap:(UIGestureRecognizer*)gestureRecognize
{
// retrieve the SCNView
SCNView *scnView = (SCNView *)self.view;
// check what nodes are tapped
CGPoint p = [gestureRecognize locationInView:scnView];
NSArray *hitResults = [scnView hitTest:p options:nil];
// check that we clicked on at least one object
if([hitResults count] > 0){
// retrieved the first clicked object
SCNHitTestResult *result = [hitResults objectAtIndex:0];
// get its material
SCNMaterial *material = result.node.geometry.firstMaterial;
[SCNTransaction begin];
[SCNTransaction setAnimationDuration:0.5];
// on completion - unhighlight
[SCNTransaction setCompletionBlock:^{
[SCNTransaction begin];
[SCNTransaction setAnimationDuration:0.5];
isSelected = YES;
[SCNTransaction commit];
}];
material.emission.contents = [UIColor redColor];
[SCNTransaction commit];
}
}
次に、選択したノードをドラッグしてみます。
- (void)handlePan:(UIPanGestureRecognizer *)gesture {
CGPoint point = [gesture velocityInView:self.view];
CGPoint p = [gesture locationInView:scene.sceneView];
// nothing selected, so spin the table node
if ( !isSelected) {
if (point.x > 0)
{
// user dragged towards the right
[nodeForRotation runAction:[SCNAction repeatAction:[SCNAction rotateByX:0 y:point.x/10000 z:0 duration:0.23] count:1]];
} else {
// user dragged towards the left
[nodeForRotation runAction:[SCNAction repeatAction:[SCNAction rotateByX:0 y:point.x/10000 z:0 duration:0.23] count:1]];
}
} else {
// node on table selected, so move this node
// retrieve the SCNView
SCNView *scnView = (SCNView *)self.view;
// check what nodes are tapped
CGPoint p = [gesture locationInView:scnView];
NSArray *hitResults = [scnView hitTest:p options:nil];
if([hitResults count] > 0){
// retrieved the first clicked object
SCNHitTestResult *result = [hitResults objectAtIndex:0];
result.node.position = SCNVector3Make(p.x,p.y,0);
}
}