Scenekit:如何检查节点朝向摄像机的方向

时间:2018-01-11 11:02:26

标签: ios objective-c scenekit scnnode

我正在我的应用中创建一个3D建模模块。我正在使用以下代码旋转节点:

-(void)handlePan:(UIPanGestureRecognizer *)gesture{

NSString *nodeName = nil;

for (SCNNode *node in _sceneView.scene.rootNode.childNodes) {
    if(node.name != nil){
        nodeName = node.name;
        break;
    }
}

SCNView *scnView = _sceneView;

SCNNode *humanNode = [scnView.scene.rootNode childNodeWithName:nodeName recursively:YES];

// get pan direction
CGPoint velocity = [gesture velocityInView:self.view];

if (panDirection ==nil) {

    panDirection = [self getPanDirection:velocity];
}
// if selected brick
if (gesture.state == UIGestureRecognizerStateBegan) {
    lastAngle = 0.0;
}

CGPoint translation = [gesture translationInView:self.view];

float anglePan = ([panDirection isEqualToString:@"horizontal"]) ?  [self deg2rad:translation.x] : [self deg2rad:translation.y];
float x = ([panDirection isEqualToString:@"vertical"]) ? 1 : 0.0;
float y = ([panDirection isEqualToString:@"horizontal"]) ?  1 : 0.0;

// calculate the angle change from last call
float fraction = anglePan - lastAngle;
lastAngle = anglePan;

NSLog(@"%f",fraction);

// perform rotation by difference to last angle
humanNode.transform = SCNMatrix4Mult(humanNode.transform, SCNMatrix4MakeRotation(fraction, x, y, 0.0));}

我想知道模型是朝向相机还是面向相机。我怎么能做到这一点?

0 个答案:

没有答案