void TestColliderDetector::initWorld()
{
    //! init physic world
	b2Vec2 noGravity(0, 0);
    
	world = new b2World(noGravity);
	world->SetAllowSleeping(true);
    
	listener = new ContactListener();
	world->SetContactListener(listener);
    
	debugDraw = new GLESDebugDraw( PT_RATIO );
	world->SetDebugDraw(debugDraw);
    
	uint32 flags = 0;
	flags += b2Draw::e_shapeBit;
	//        flags += b2Draw::e_jointBit;
	//        flags += b2Draw::e_aabbBit;
	//        flags += b2Draw::e_pairBit;
	//        flags += b2Draw::e_centerOfMassBit;
	debugDraw->SetFlags(flags);
    
    
	//! Define the dynamic body.
	//! Set up a 1m squared box in the physics world
	b2BodyDef bodyDef;
	bodyDef.type = b2_dynamicBody;
    
	b2Body *body = world->CreateBody(&bodyDef);
    
	//! Define another box shape for our dynamic body.
	b2PolygonShape dynamicBox;
    //define bullet's body shape
	dynamicBox.SetAsBox(.5f, .5f);
    
	//! Define the dynamic body fixture.
	b2FixtureDef fixtureDef;
	fixtureDef.shape = &dynamicBox;
	fixtureDef.isSensor = true;
	body->CreateFixture(&fixtureDef);
    
    //! set body to bullet and add it to world
	bullet->setB2Body(body);
	bullet->setPTMRatio(PT_RATIO);
	bullet->setPosition( ccp( -100, -100) );
    
	body = world->CreateBody(&bodyDef);
	armature2->setB2Body(body);
}
Пример #2
0
void PhysicsWorld::initNoGravityWorld()
{
	b2Vec2 noGravity(0, 0);

	m_pNoGravityWorld = new b2World(noGravity);
	m_pNoGravityWorld->SetAllowSleeping(true);

	m_pContactListener = new ContactListener();
	m_pNoGravityWorld->SetContactListener(m_pContactListener);


#if ENABLE_PHYSICS_DEBUG
	m_pDebugDraw = new GLESDebugDraw( PT_RATIO );
	m_pNoGravityWorld->SetDebugDraw(m_pDebugDraw);

	uint32 flags = 0;
	flags += b2Draw::e_shapeBit;
	//        flags += b2Draw::e_jointBit;
	//        flags += b2Draw::e_aabbBit;
	//        flags += b2Draw::e_pairBit;
	//        flags += b2Draw::e_centerOfMassBit;
	m_pDebugDraw->SetFlags(flags);
#endif
}