Reputation: 4732
I have a gesture recignizer, and I need to rotate a body:
- (void) rotate:(UIGestureRecognizer*)recognizer node:(CCNode*)node
{
b2Body *body = (b2Body*)[node.parent userData];
UIRotationGestureRecognizer* rotate = (UIRotationGestureRecognizer*)recognizer;
b2Vec2 pos = body->GetPosition();
body->SetTransform(pos, (- rotate.rotation));
}
offcorse, when I starting rotation, it starts from zero angle. *But how to continue rotation from current angle? * I cant just add rotate.rotation
to tu current angle: this method called on every move, and angle is calculated from very begining of gesture. keep track on actual current angle (without anctive gesture's angle), will be a pretty hard task, I think
Upvotes: 1
Views: 982
Reputation: 4732
I found solution: I checked state of gesture (there is a begining state):
- (void) rotate:(UIGestureRecognizer*)recognizer node:(CCNode*)node
{
b2Body *body = (b2Body*)[node.parent userData];
UIRotationGestureRecognizer* rotate = (UIRotationGestureRecognizer*)recognizer;
if (rotate.state == UIGestureRecognizerStateBegan)
{
baseAngle = body->GetAngle();
}
b2Vec2 pos = body->GetPosition();
body->SetTransform(pos, (baseAngle - rotate.rotation));
}
Upvotes: 1