本文整理汇总了C++中b2Body类的典型用法代码示例。如果您正苦于以下问题:C++ b2Body类的具体用法?C++ b2Body怎么用?C++ b2Body使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了b2Body类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: keyDown
bool keyDown (int keyCode) {
if (keyCode == gdx_cpp::Input::Keys::COMMA) {
if (m_bullet != NULL) {
world->DestroyBody(m_bullet);
m_bullet = NULL;
}
{
b2CircleShape * shape = new b2CircleShape();
shape->m_radius = 0.25f;
b2FixtureDef fd;
fd.shape = shape;
fd.density = 20.0f;
fd.restitution = 0.05f;
b2BodyDef bd;
bd.type = b2_dynamicBody;
bd.bullet = true;
bd.position.Set(-31, 5);
m_bullet = world->CreateBody(&bd);
m_bullet->CreateFixture(&fd);
m_bullet->SetLinearVelocity(b2Vec2(400, 0));
}
}
return false;
}
示例2: Car
//constructor
Car(b2World* world){
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
w_body = world->CreateBody(&bodyDef);
b2PolygonShape polygonShape;
polygonShape.SetAsBox(0.5f, 1.25f);
b2Fixture* fixture = w_body->CreateFixture(&polygonShape, 1);//shape, density
fixture->SetUserData(new CarTireFUD());
w_body->SetUserData(this);
currentTraction = 1;
}
示例3: Pelota
Pelota(b2World* _world ,RenderWindow *_wnd){
//guardamos puntero a ventana para dibujar luego
wnd=_wnd;
_image= new Image();
_image->LoadFromFile("pelota.jpg");
//cargamos el sprite
_sprite= new Sprite(*_image);
//definimos el body y lo creamos
b2BodyDef bodyDef;
bodyDef.type = b2_dynamicBody;
bodyDef.position.Set(100.0f, 0.0f);
_body = _world->CreateBody(&bodyDef);
//creamos su figura de colisión
//en este caso suponemos que la figura de
//colision es una caja cuadrada
b2PolygonShape dynamicBox;
dynamicBox.SetAsBox(20.0f, 20.0f);
//creamos el fixture, le seteamos
//la figura de colision
//y agregamos el fixture al body
b2FixtureDef fixtureDef;
fixtureDef.shape = &dynamicBox;
fixtureDef.density = 10.0f;
fixtureDef.friction = 0.3f;
fixtureDef.restitution=1.0f;
_body->CreateFixture(&fixtureDef);
}
示例4: CreateFixture
Value CreateFixture(b2Body &body, b2Shape &shape)
{
auto fixture = body.CreateFixture(&shape, 1.0f);
auto r = new Renderable("color");
fixture->SetUserData(r);
return Value((int)fixtures->Add(fixture));
}
示例5: generateId
void Box2dContainer::assignNode(b2Body& body, cocos2d::Node& node)
{
if (!nodeToId.count(&node)) {
auto newId = generateId();
nodeToId[&node] = newId;
idToNode[newId] = &node;
}
body.SetUserData(static_cast<void*>(nodeToId[&node]));
}
示例6: Ball
Ball(b2World* world, float radius) {
m_body = NULL;
m_radius = radius;
b2BodyDef myBodyDef;
myBodyDef.type = b2_dynamicBody;
myBodyDef.position.Set(0, 20);
m_body = world->CreateBody(&myBodyDef);
m_contacting = false;
//add circle fixture
b2CircleShape circleShape;
circleShape.m_p.Set(0, 0);
circleShape.m_radius = m_radius; //use class variable
b2FixtureDef myFixtureDef;
myFixtureDef.shape = &circleShape;
myFixtureDef.density = 1;
m_body->CreateFixture(&myFixtureDef);
m_body->SetUserData( this );
}
示例7: CreateFixture
Value CreateFixture(VM &vm, b2Body &body, b2Shape &shape) {
auto fixture = body.CreateFixture(&shape, 1.0f);
auto po = new PhysicsObject(Renderable("color"), fixture);
fixture->SetUserData(po);
return Value(vm.NewResource(po, &physics_type));
}
示例8: CreateGroundBox
// Create a horizontal box fixture attached to the ground body.
b2Fixture* BodyContactTests::CreateGroundBox()
{
b2Assert(m_groundBody);
b2PolygonShape shape;
shape.SetAsBox(10.0f * m_particleDiameter, m_particleDiameter);
return m_groundBody->CreateFixture(&shape, 0.0f);
}
示例9: CreateValley
// Create a valley (similar to the Anti-Pointy test in the Testbed) and
// attach to the ground body.
void BodyContactTests::CreateValley()
{
b2Assert(m_groundBody);
float32 i;
const float32 step = 1.0f;
for (i = -10.0f; i < 10.0f; i+=step)
{
b2PolygonShape shape;
const b2Vec2 vertices[] = {
b2Vec2(i, -10.0f),
b2Vec2(i+step, -10.0f),
b2Vec2(0.0f, 15.0f)
};
shape.Set(vertices, B2_ARRAY_SIZE(vertices));
m_groundBody->CreateFixture(&shape, 0.0f);
}
for (i = -10.0f; i < 35.0f; i+=step)
{
b2PolygonShape shape;
const b2Vec2 vertices[] = {
b2Vec2(-10.0f, i),
b2Vec2(-10.0f, i+step),
b2Vec2(0.0f, 15.0f)
};
shape.Set(vertices, B2_ARRAY_SIZE(vertices));
m_groundBody->CreateFixture(&shape, 0.0f);
const b2Vec2 vertices2[] = {
b2Vec2(10.0f, i),
b2Vec2(10.0f, i+step),
b2Vec2(0.0f, 15.0f)
};
shape.Set(vertices2, B2_ARRAY_SIZE(vertices2));
m_groundBody->CreateFixture(&shape, 0.0f);
}
}
示例10: block
block(float w,float h,float x,float y,int a, b2World* m_world,int s_d=0, float friction =1.0f,float density=1.0f)
{
b2PolygonShape shape;
shape.SetAsBox(w, h);
bd.angle = a; //set the starting angle
bd.position.Set(x, y);
if(s_d==1)bd.type = b2_dynamicBody;
if(s_d==0)bd.type = b2_staticBody;
body = m_world->CreateBody(&bd);
b2FixtureDef *fd = new b2FixtureDef;
fd->density = density;
fd->shape = new b2PolygonShape;
fd->shape = &shape;
fd->friction = friction;
fd->restitution = 0.0f;
body->CreateFixture(fd);
}
示例11: updateDrive
void updateDrive(int controlState) {
//find desired speed
float desiredSpeed = 0;
switch (controlState & (TDC_UP | TDC_DOWN)) {
case TDC_UP: desiredSpeed = maxForwardSpeed; break;
case TDC_DOWN: desiredSpeed = maxBackwardSpeed; break;
default: return;//do nothing
}
//find current speed in forward direction
b2Vec2 currentForwardNormal = w_body->GetWorldVector(b2Vec2(0, 1));
float currentSpeed = b2Dot(getForwardVelocity(), currentForwardNormal);
//apply necessary force
float force = 0;
if (desiredSpeed > currentSpeed)
force = maxDriveForce;
else if (desiredSpeed < currentSpeed)
force = -maxDriveForce;
else
return;
//w_body->ApplyForce(currentTraction * force * currentForwardNormal, w_body->GetWorldCenter());
}
示例12: getLateralVelocity
b2Vec2 getLateralVelocity() {
b2Vec2 currentRightNormal = w_body->GetWorldVector(b2Vec2(1, 0));
return b2Dot(currentRightNormal, w_body->GetLinearVelocity()) * currentRightNormal;
}
示例13: ActualizarPosiciones
//metodo que posiciona el sprites
//segun la posicion del body
void ActualizarPosiciones(){
b2Vec2 pos=_body->GetPosition();
_sprite->SetPosition(pos.x,pos.y);
}
示例14:
//destructor
~Car(){
w_body->GetWorld()->DestroyBody(w_body);
}
示例15: applyForceToCenter
/// Apply a force to the center of the rigid body
virtual void applyForceToCenter(Vector2D force)
{
_body->ApplyLinearImpulse(b2Vec2(force.x, force.y), _body->GetLocalCenter());
}