本文整理汇总了C++中Body::finish方法的典型用法代码示例。如果您正苦于以下问题:C++ Body::finish方法的具体用法?C++ Body::finish怎么用?C++ Body::finish使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Body
的用法示例。
在下文中一共展示了Body::finish方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createSolidWall
void Physics::createSolidWall(b2Vec2 position, float rotation,
b2Vec2 size, bool isWorkspace=false)
{
Body wall;
wall.setType(WALL);
b2BodyDef wallDef; //static body by default
wallDef.position.Set(position.x,position.y);
wallDef.angle = rotation;
b2Body* wallBody = world->CreateBody(&wallDef);
b2PolygonShape wallShape;
wallShape.SetAsBox(size.x,size.y);
b2FixtureDef wallFixtureDef;
wallFixtureDef.shape = &wallShape;
wallBody->CreateFixture(&wallFixtureDef);
wall.addNode(wallBody);
wall.finish();
wall.setName("Wall");
wall.setWallPosition(rotation*180/pi);
if(isWorkspace)
{
workspaceWalls.append(wall);
}else
{
bodyList.append(wall);
emit objectListUpdated(bodyList);
}
}
示例2: createBall
void Physics::createBall(b2Vec2 position,float radius, float stiffness,
float damping, float density, float maxSpacing)
{
Body ball;
ball.setType(BALL);
float nodeRadius = maxSpacing*.45;
ball.setNodeRadius(nodeRadius);
float mass(density*radius*radius);
int nodeCount = (2*pi*radius/maxSpacing); //not including center
float nodeDensity(mass/(nodeRadius*nodeRadius*(nodeCount+1)));
b2BodyDef ballNodeDef;
ballNodeDef.linearDamping = 1;
ballNodeDef.angularDamping = 1;
b2CircleShape ballNodeShape;
ballNodeShape.m_radius = nodeRadius;
b2FixtureDef ballFixtureDef;
ballFixtureDef.shape = &ballNodeShape;
ballFixtureDef.density = nodeDensity;
ballNodeDef.type = b2_dynamicBody;
b2DistanceJointDef nodeLinkDef;
b2MotorJointDef nodeLinkMotorDef;
// Smaller stiffness in the link from the center to the edge
// So that the effector can deform the ball without penetrating it
nodeLinkDef.frequencyHz = sqrt((stiffness)*FORCE_FACTOR/mass);
nodeLinkDef.dampingRatio = damping;
nodeLinkMotorDef.correctionFactor = stiffness;
nodeLinkMotorDef.maxForce = stiffness*radius;
nodeLinkMotorDef.maxTorque = 0;
//center
ballNodeDef.position.Set(position.x,position.y);
b2Body* ballCenter = world->CreateBody(&ballNodeDef);
ballCenter->CreateFixture(&ballFixtureDef);
ball.addNode(ballCenter);
//circle
b2Vec2 nodePosition;
//b2Body* firstNode =ballCenter,lastNode = ballCenter;
for(int i(0);i<nodeCount;i++)
{
ballNodeDef.type = b2_dynamicBody;
nodePosition = position + radius*b2Vec2(cos(2*pi*i/nodeCount),
sin(2*pi*i/nodeCount));
ballNodeDef.position.Set(nodePosition.x,nodePosition.y);
b2Body* ballNode = world->CreateBody(&ballNodeDef);
ballNode->CreateFixture(&ballFixtureDef);
nodeLinkDef.Initialize(ballCenter,ballNode,
ballCenter->GetWorldCenter(),
ballNode->GetWorldCenter());
world->CreateJoint(&nodeLinkDef);
nodeLinkMotorDef.Initialize(ballCenter,ballNode);
world->CreateJoint(&nodeLinkMotorDef);
if(i>0)
{
nodeLinkDef.Initialize(ballNode,ball.getNode(i-1),
ballNode->GetWorldCenter(),
ball.getNode(i-1)->GetWorldCenter());
world->CreateJoint(&nodeLinkDef);
nodeLinkMotorDef.Initialize(ballNode,ball.getNode(i-1));
world->CreateJoint(&nodeLinkMotorDef);
}
ball.addNode(ballNode);
}
nodeLinkDef.Initialize(ball.getNode(nodeCount-1),ball.getNode(1),
ball.getNode(nodeCount-1)->GetWorldCenter(),
ball.getNode(1)->GetWorldCenter());
world->CreateJoint(&nodeLinkDef);
nodeLinkMotorDef.Initialize(ball.getNode(nodeCount-1),ball.getNode(1));
world->CreateJoint(&nodeLinkMotorDef);
ball.finish();
ball.setName("Ball");
ball.setTransform(physics2graphics);
bodyList.append(ball);
emit objectListUpdated(bodyList);
}