gpt4 book ai didi

iphone - BOX2D 静态体摩擦

转载 作者:行者123 更新时间:2023-11-28 08:18:51 25 4
gpt4 key购买 nike

我正在创建一个像这样的地面体:

    // Define the ground body.
b2BodyDef groundBodyDef;
groundBodyDef.position.Set(0, 0); // bottom-left corner

// Call the body factory which allocates memory for the ground body
// from a pool and creates the ground box shape (also from a pool).
// The body is also added to the world.
b2Body* groundBody = world->CreateBody(&groundBodyDef);

// Define the ground box shape.
b2PolygonShape groundBox;

// bottom
groundBox.SetAsEdge(b2Vec2(0,0), b2Vec2(screenSize.width/PTM_RATIO,0));
groundBody->CreateFixture(&groundBox,0);

// top
groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width/PTM_RATIO,screenSize.height/PTM_RATIO));
groundBody->CreateFixture(&groundBox,0);

// left
groundBox.SetAsEdge(b2Vec2(0,screenSize.height/PTM_RATIO), b2Vec2(0,0));
groundBody->CreateFixture(&groundBox,0);

// right
groundBox.SetAsEdge(b2Vec2(screenSize.width/PTM_RATIO,screenSize.height/PTM_RATIO), b2Vec2(screenSize.width/PTM_RATIO,0));
groundBody->CreateFixture(&groundBox,0);

如何设置它的摩擦力?谢谢。

最佳答案

您需要根据夹具定义 (b2FixtureDef) 创建夹具,您可以在其中设置特定的摩擦力。像这样:

b2FixtureDef fixtureDef;

fixtureDef.shape = &groundBox;
fixtureDef.density = 0.0f;
fixtureDef.friction = YOUR_FRICTION_VALUE;

groundBody->CreateFixture(&fixtureDef);

关于iphone - BOX2D 静态体摩擦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6695228/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com