在iOS中将节点对象旋转到初始位置SCNScene

时间:2017-08-23 15:12:34

标签: ios scnscene

我有三维模型的骨架,我在我的应用程序中用作节点。我使用UIPanGesture使用此代码

旋转它
- (void)handleSingleTap:(UIPanGestureRecognizer *)recognizer
{
    CGPoint location = [recognizer locationInView:[recognizer.view superview]];
    float x = location.x;
    float y = location.y;
    float anglePan = sqrt(pow(x, 2)*M_PI_4/90.0 + pow(y, 2));//*M_PI/180.0;
    SCNVector4 rotationVector = SCNVector4Make(0, 1, 0, anglePan);

    geometryNode.rotation = rotationVector;
    muscleNode.rotation = rotationVector;

    if(recognizer.state == UIGestureRecognizerStateEnded){

        SCNMatrix4 currentPivot1 = geometryNode.pivot;
        SCNMatrix4 changePivot1 = 
        SCNMatrix4Invert(geometryNode.transform);
        geometryNode.pivot = SCNMatrix4Mult(changePivot1, currentPivot1);
        geometryNode.transform = SCNMatrix4Identity;

        SCNMatrix4 currentPivot2 = muscleNode.pivot;
        SCNMatrix4 changePivot2 = SCNMatrix4Invert(muscleNode.transform);
        muscleNode.pivot = SCNMatrix4Mult(changePivot2, currentPivot2);
        muscleNode.transform = SCNMatrix4Identity;
    }
}

现在我想将我的骨架旋转到刚开始时的初始位置。请指导我完成整个过程。谢谢

0 个答案:

没有答案