[英]box2d body rotation
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. *我不能仅将rotate.rotation
添加到当前角度:此方法在每次移动时都会调用,并且角度是从手势的最开始算起的。 keep track on actual current angle (without anctive gesture's angle), will be a pretty hard task, I think 我认为要跟踪当前的当前角度(没有活动手势的角度),将是一项艰巨的任务
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));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.