Thursday, January 7, 2010

create body IPhone

// body
b2BodyDef groundBodyDef2;
groundBodyDef2.position.Set(8, 9);
groundBodyDef2.angle=28;
//groundBox2.restitution=1;
b2Body* groundBody2 = world->CreateBody(&groundBodyDef2);
b2PolygonShape groundBox2;
groundBox2.SetAsBox(1.5f, .1f);//SetAsEdge(b2Vec2(3,3), b2Vec2(3,0));
groundBody2->CreateFixture(&groundBox2);


// triangle
b2BodyDef polyBodyDef; // Define the body
polyBodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO);
b2Body *poly = world->CreateBody(&polyBodyDef);

b2PolygonShape polyShapeDef; // Define the shape
//polyShapeDef.SetAsBox(1.0f, 1.0f);
polyShapeDef.m_vertexCount = 3;
polyShapeDef.m_vertices[0].Set(-1, 0);
polyShapeDef.m_vertices[1].Set(1, 0);
polyShapeDef.m_vertices[2].Set(0, 1.5);

b2FixtureDef polyFixtureDef; // Define the fixture
polyFixtureDef.shape = &polyShapeDef;
polyFixtureDef.density = 1.0f;
polyFixtureDef.friction = 0.3f;

poly->CreateFixture(&polyFixtureDef);

No comments:

FEEDJIT Live