I am creating a 3D modeling module in my app. I am rotating the Node with following code:
-(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));}
I want to know if the Model is facing as front toward the camera or as back from the camera. How can I accomplish this?