Box2D Typecast:ApplyForce()反引力

时间:2014-04-12 22:16:00

标签: objective-c cocos2d-iphone box2d

我在这里遇到了一个类型问题,而且我整天都在打破它。问题在于ApplyForce功能。我们无法将b2Vec2(重力)与浮子(质量)相乘。我按照例子here有人可以帮助我吗?

-(void) antiGravity
{
float32 total_mass = [cannonBallBody getMass];
b2Vec2 point0 = [cannonBallBody getWorldCenter: cannonBallBody];
cannonBallBody -> ApplyForce(-1 * world -> GetGravity() * total_mass, cannonBallBody -> GetWorldCenter());
}

使用类型为b2Body *的CannonBallBody和

- (float) getMass{
float total_mass = 0;
for(int i=0; i<8; i++){
            total_mass+= body1[i]-> GetMass();
    }
return total_mass;
 }

- (b2Vec2) getWorldCenter: (b2Body*)body{
    return body->GetWorldCenter();
 }

谢谢!

1 个答案:

答案 0 :(得分:0)

我不太明白这个问题,因为你没有说出这导致的错误。

但我猜你只需要将浮点数放在向量之前。原因是Box2D定义了这个运算符,但不是相反的:

inline b2Vec2 operator * (float32 s, const b2Vec2& a)
{
    return b2Vec2(s * a.x, s * a.y);
}
相关问题