// 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); }
void createWorld (b2World& world) { m_stepCount = 0; m_angularVelocity = 0; { b2BodyDef bd; bd.position.Set(0, 0); b2Body * body = world.CreateBody(&bd); b2PolygonShape * shape = new b2PolygonShape(); shape->SetAsEdge(b2Vec2(-10, 0), b2Vec2(10, 0)); body->CreateFixture(shape, 0); shape->SetAsBox(0.2f, 1.0f, b2Vec2(0.5f, 1.0f), 0); body->CreateFixture(shape, 0); delete shape; } { b2BodyDef bd; bd.type = b2_dynamicBody; bd.position.Set(0, 20); b2PolygonShape * shape = new b2PolygonShape(); shape->SetAsBox(2, 0.1f); m_body = world.CreateBody(&bd); m_body->CreateFixture(shape, 1); m_angularVelocity = 33.468121f; m_body->SetLinearVelocity(b2Vec2(0, -100)); m_body->SetAngularVelocity(m_angularVelocity); delete shape; } }
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; }
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)); }
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); }
//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; }
// 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); } }
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 ); }
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); }
b2Fixture * operator()(const CollisionPolygonDef & aDef) const { b2Fixture *fixture = mBody->CreateFixture(&aDef.mFixture); fixture->SetUserData(mBody->GetUserData()); return fixture; }
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)); }