旋转X Y轴上的对象,cocos3D

时间:2013-03-27 14:45:57

标签: rotation gesture pan cocos3d

我在iOs上使用Cocos3D。我需要使用平移手势旋转对象。

switch (gesture.state)
{
    case UIGestureRecognizerStateBegan:
        saveState = Dobj.rotation;
    break;
    case UIGestureRecognizerStateChanged:
        CC3Vector rotateVector = CC3VectorMake(gesture.translation.y, gesture.translation.x, 0.0f);
        Dobj.rotation = CC3VectorAdd(saveState, rotateVector);
    break;
    case UIGestureRecognizerStateEnded:
    break;
    default:
    break;
}

这样我可以让我的对象(Dobj)自行旋转。但似乎轴也在旋转,这导致一些非常奇怪的旋转。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

所以这就是我解决问题的方法。

switch (gesture.state)
{
    case UIGestureRecognizerStateBegan:
        saveState = CC3VectorMake(0.0f, 0.0f, 0.0f);
    break;
    case UIGestureRecognizerStateChanged:
         CC3Vector rotateVector = CC3VectorMake(gesture.translation.y, gesture.translation.x, 0.0f);
        [Dobj rotateBy:CC3VectorDifference(rotateVector, saveState)];
        saveState = rotateVector;
    break;
    case UIGestureRecognizerStateEnded:
    break;
    default:
    break;
}

使用方法rotateBy:似乎只旋转对象而不更改其轴