0

So I'm using Cocos3D in Obj-C.

Since my initial question doesn't seems to be clear enough to get any answers i write it again.

I'm making a 3D viewer, with this i want to be able to drag my finger on the screen and make my object(Dobj) rotates on itself.

-(void) startRotatingObjectOnXYAxis { saveXYAxisStartLocation = Dobj.rotation; }
-(void) rotateObjectOnXYAxisBy: (CGPoint) aMovement
{
    CC3Vector rotateVector = CC3VectorMake(aMovement.y, aMovement.x, 0.0f);
    Dobj.rotation = CC3VectorAdd(saveXYAxisStartLocation, rotateVector);
}

The problem is that when I do it this way, the object axis also rotates, and some drags after, the X axis will be vertical(instead of horizontal), and rotations become very confusing.

So i would like to reset the axis to their origin point after each drags.

Something like that:

-(void) startRotatingObjectOnXYAxis { saveXYAxisStartLocation = Dobj.rotation; }
-(void) rotateObjectOnXYAxisBy: (CGPoint) aMovement
{
    [Dobj moveMeshOriginTo:CC3VectorMake(0.0f, 0.0f, saveXYAxisStartLocation.z)];
    CC3Vector rotateVector = CC3VectorMake(aMovement.y, aMovement.x, 0.0f);
    Dobj.rotation = CC3VectorAdd(saveXYAxisStartLocation, rotateVector);
}

But it doesn't have any effect ...

In my examples aMovement is the (UIPanGestureRecognizer*) gesture.translation value.

Micka
  • 1,648
  • 1
  • 19
  • 34

1 Answers1

0

Ok I finally ended with this solution:

-(void) startRotatingObjectOnXYAxis { objectXYAxisStartRotation =  CC3VectorMake(0.0f, 0.0f, 0.0f); }
-(void) rotateObjectOnXYAxisBy: (CGPoint) aMovement
{
    CC3Vector rotateVector = CC3VectorMake(aMovement.y, aMovement.x, 0.0f);
    [Dobj rotateBy:CC3VectorDifference(rotateVector, objectXYAxisStartRotation)];
    objectXYAxisStartRotation = rotateVector;
}

It appears that rotateBy will rotate the object only, without rotating the axis. So the problem is SOLVED

Micka
  • 1,648
  • 1
  • 19
  • 34