Question

I'm using Cocos3D on iOs. I need to rotate an object using pan gesture.

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;
}

This way I can get my object(Dobj) to rotate on itself. But it seems that the axis is also rotating and that is causing some really weird rotation.

How can I fix this ?

Was it helpful?

Solution

So here is how I solved my problem.

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;
}

Using the method rotateBy: seems to rotate the object only without changing its axis

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top