wsScene::wsScene(vec4 myGravity) {
  gravity = myGravity;
  cameras = wsNew(wsHashMap<wsCamera*>, wsHashMap<wsCamera*>(WS_MAX_CAMERAS));
  models = wsNew(wsHashMap<wsModel*>, wsHashMap<wsModel*>(WS_MAX_MODELS));
  primitives = wsNewArray(wsPrimitive*, WS_MAX_PRIMITIVES);
  //  Instantiate physics engine
  #if WS_PHYSICS_BACKEND == WS_BACKEND_BULLET
    rigidBodies = wsNew(wsHashMap<btRigidBody*>, wsHashMap<btRigidBody*>(WS_MAX_MODELS));
    broadphase = wsNew(btDbvtBroadphase,  btDbvtBroadphase());
    collisionConfig = wsNew(btDefaultCollisionConfiguration, btDefaultCollisionConfiguration());
    dispatcher = wsNew(btCollisionDispatcher, btCollisionDispatcher(collisionConfig));
    solver = wsNew(btSequentialImpulseConstraintSolver, btSequentialImpulseConstraintSolver());
    physicsWorld = wsNew(btDiscreteDynamicsWorld, btDiscreteDynamicsWorld(dispatcher, broadphase, solver, collisionConfig));
    physicsWorld->setGravity(btVector3(gravity.x, gravity.y, gravity.z));
  #endif
  numPrimitives = 0;
}
Пример #2
0
bool BulletPhysics::Initialize()
{
	LoadXml();

	// this object controls bullet SDK's internal memory management during collision pass
	m_CollisionConfiguration.reset(CB_NEW btDefaultCollisionConfiguration);

	// this manages how bullet detects precise collisions between pairs of objects
	m_Dispatcher.reset(CB_NEW btCollisionDispatcher(m_CollisionConfiguration.get()));

	// used to quickly detect collisions between object, imprecisely. 
	// if a collision passes this phase it will be passed to the dispatcher
	m_Broadphase.reset(CB_NEW btDbvtBroadphase);

	m_Solver.reset(CB_NEW btSequentialImpulseConstraintSolver);

	// this is the main interface point for the physics world
	m_DynamicsWorld.reset(CB_NEW btDiscreteDynamicsWorld(m_Dispatcher.get(), 
		m_Broadphase.get(), m_Solver.get(), m_CollisionConfiguration.get()));

	m_DebugDrawer.reset(CB_NEW BulletDebugDrawer);
	m_DebugDrawer->ReadOptions();

	if (!m_CollisionConfiguration || !m_Dispatcher || !m_Broadphase || !m_Solver
		|| !m_DynamicsWorld /*|| !m_DebugDrawer*/)
	{
		CB_ERROR("BulletPhysics::Initialize failed");
		return false;
	}

	m_DynamicsWorld->setDebugDrawer(m_DebugDrawer.get());

	// set internal tick callback to our own method
	m_DynamicsWorld->setInternalTickCallback(BulletPhysics::BulletInternalTickCallback);
	m_DynamicsWorld->setWorldUserInfo(this);

	return true;
}