コード例 #1
0
ファイル: PhysicsUtil.cpp プロジェクト: caomw/osgPhysX
PxScene* createScene( const osg::Vec3& gravity, const PxSimulationFilterShader& filter,
                      physx::PxSceneFlags flags, unsigned int numThreads, bool useGPU )
{
    PxSceneDesc sceneDesc( SDK_OBJ->getTolerancesScale() );
    sceneDesc.gravity = PxVec3(gravity[0], gravity[1], gravity[2]);
    sceneDesc.filterShader = filter;
    sceneDesc.flags |= flags;

#if USE_PHYSX_33
    if ( useGPU )
    {
        PxCudaContextManager* cudaManager = Engine::instance()->getOrCreateCudaContextManager();
        if ( cudaManager ) sceneDesc.gpuDispatcher = cudaManager->getGpuDispatcher();
    }
#endif

    if ( !sceneDesc.gpuDispatcher && !sceneDesc.cpuDispatcher )
    {
        PxDefaultCpuDispatcher* defCpuDispatcher = PxDefaultCpuDispatcherCreate(numThreads);
        if ( !defCpuDispatcher )
           OSG_WARN << "Failed to create default Cpu dispatcher." << std::endl;
        sceneDesc.cpuDispatcher = defCpuDispatcher;
    }
    
    PxScene* scene = SDK_OBJ->createScene( sceneDesc );
    if ( !scene )
    {
        OSG_WARN << "Failed to create the physics world." << std::endl;
        return NULL;
    }
    scene->setVisualizationParameter( PxVisualizationParameter::eSCALE, 1.0f );
    scene->setVisualizationParameter( PxVisualizationParameter::eCOLLISION_SHAPES, 1.0f );
    return scene;
}
コード例 #2
0
ファイル: wrap.cpp プロジェクト: dexset/physxwrap
PxScene* getScene( PxPhysics* physics )
{
    PxSceneDesc scene_desc( physics->getTolerancesScale() );
    scene_desc.cpuDispatcher = PxDefaultCpuDispatcherCreate(1);
    scene_desc.filterShader = PxDefaultSimulationFilterShader;
    return physics->createScene( scene_desc );
}
コード例 #3
0
bool PhysXPhysics::VInitialize()
{
	VLoadPhysicsConfigXml();
	int version = PX_PHYSICS_VERSION;
	m_pFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, m_allocatorCallback, m_errorCallback);
	m_pPhysicsSdk = PxCreatePhysics(PX_PHYSICS_VERSION, *m_pFoundation, PxTolerancesScale(), true);

	if (!m_pPhysicsSdk)
	{
		BE_ERROR("Error Creating PhysX device.");
		return false;
	}

	PxSceneDesc sceneDesc(m_pPhysicsSdk->getTolerancesScale());

	sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f); //Set Gravity
	m_pDispatcher = PxDefaultCpuDispatcherCreate(2);
	sceneDesc.cpuDispatcher = m_pDispatcher;
	sceneDesc.filterShader = PxDefaultSimulationFilterShader;

	m_pScene = m_pPhysicsSdk->createScene(sceneDesc);

#ifdef ENABLE_PHYSX_PVD
	ConnectPVD();
#endif
	
	return true;
}
コード例 #4
0
ファイル: apex.cpp プロジェクト: schulchr/Olympus
bool Apex::CreateScene()
{
	PxSceneDesc sceneDesc(mPhysics->getTolerancesScale());
    sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);

    if(!sceneDesc.cpuDispatcher)
    {
        mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
        if(!mCpuDispatcher)
            return false;
        sceneDesc.cpuDispatcher    = mCpuDispatcher;
    }

    if(!sceneDesc.filterShader)
    {
        sceneDesc.filterShader = PxDefaultSimulationFilterShader;
    }
    
    /*#ifdef PX_WINDOWS
    if(!sceneDesc.gpuDispatcher && mCudaContextManager)
    {
        sceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();
    }
    #*/
    mProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mFoundation);
    pxtask::CudaContextManagerDesc cudaContextManagerDesc;
    mCudaContextManager = pxtask::createCudaContextManager(*mFoundation,cudaContextManagerDesc, mProfileZoneManager);
    sceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();


	mScene.push_back(mPhysics->createScene(sceneDesc));

    if (!mScene[mCurrentScene])
        return false;


	 NxApexSceneDesc apexSceneDesc;
    // Create the APEX scene...
    
    apexSceneDesc.scene = mScene[mCurrentScene];
	
    if(apexSceneDesc.isValid())
		gApexScene.push_back(gApexSDK->createScene(apexSceneDesc));
    else
        return false;

    if(!gApexScene[mCurrentScene])
        return false;

	gApexScene[mCurrentScene]->setLODResourceBudget(10000.f);

	static const physx::PxU32 viewIDlookAtRightHand = gApexScene[mCurrentScene]->allocViewMatrix(physx::apex::ViewMatrixType::LOOK_AT_LH);
	static const physx::PxU32 projIDperspectiveCubicRightHand = gApexScene[mCurrentScene]->allocProjMatrix(physx::apex::ProjMatrixType::USER_CUSTOMIZED);

	gApexScene[mCurrentScene]->setUseViewProjMatrix(viewIDlookAtRightHand, projIDperspectiveCubicRightHand);
}
コード例 #5
0
ファイル: Physics.cpp プロジェクト: RoyKirk/AIEWork
void Physics::SetUpPhysX()
{
	PxAllocatorCallback *myCallback = new myAllocator();
	g_PhysicsFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, *myCallback, gDefaultErrorCallback);
	g_Physics = PxCreatePhysics(PX_PHYSICS_VERSION, *g_PhysicsFoundation, PxTolerancesScale());
	PxInitExtensions(*g_Physics);
	//create physics material
	g_PhysicsMaterial = g_Physics->createMaterial(0.5f, 0.5f, 0.5f);
	PxSceneDesc sceneDesc(g_Physics->getTolerancesScale());
	sceneDesc.gravity = PxVec3(0, -10.0f, 0);
	sceneDesc.filterShader = &physx::PxDefaultSimulationFilterShader;
	sceneDesc.cpuDispatcher = PxDefaultCpuDispatcherCreate(1);
	g_PhysicsScene = g_Physics->createScene(sceneDesc);
}
コード例 #6
0
// Set up PhysX
void InitializePhysX() {
	gFoundation = PxCreateFoundation(PX_FOUNDATION_VERSION, gAllocator, gErrorCallback);

	gPvd = PxCreatePvd(*gFoundation);
	PxPvdTransport* transport = PxDefaultPvdSocketTransportCreate("127.0.0.1", 5425, 10);
	gPvd->connect(*transport, PxPvdInstrumentationFlag::eALL);

	gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(), true, gPvd);

	PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
	sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
	gDispatcher = PxDefaultCpuDispatcherCreate(2);
	sceneDesc.cpuDispatcher = gDispatcher;
	sceneDesc.filterShader = contactReportFilterShader/*PxDefaultSimulationFilterShader*/;
	sceneDesc.simulationEventCallback = &gContactReportCallback;	// contact callback
	sceneDesc.contactModifyCallback = &gModContactReportCallback;	// modification contact callback
	gScene = gPhysics->createScene(sceneDesc);

	PxPvdSceneClient* pvdClient = gScene->getScenePvdClient();
	if (pvdClient)
	{
		pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_CONSTRAINTS, true);
		pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_CONTACTS, true);
		pvdClient->setScenePvdFlag(PxPvdSceneFlag::eTRANSMIT_SCENEQUERIES, true);
	}
	gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f);

	// add some physics objects
	AddPhyObjects();

	createChain(PxTransform(PxVec3(10.0f, 30.0f, -30.0f)), 5, PxBoxGeometry(2.0f, 0.5f, 0.5f), 4.0f, createLimitedSpherical);
	createChain(PxTransform(PxVec3(0.0f, 30.0f, -30.0f)), 5, PxBoxGeometry(2.0f, 0.5f, 0.5f), 4.0f, createBreakableFixed);
	createChain(PxTransform(PxVec3(-10.0f, 30.0f, -30.0f)), 5, PxBoxGeometry(2.0f, 0.5f, 0.5f), 4.0f, createDampedD6);

	gScene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1.0f);
	gScene->setVisualizationParameter(PxVisualizationParameter::eACTOR_AXES, 1.0f);
	gScene->setVisualizationParameter(PxVisualizationParameter::eCOLLISION_SHAPES, 2.0f);
	gScene->setVisualizationParameter(PxVisualizationParameter::eCONTACT_NORMAL, 2.0f);


}
コード例 #7
0
ファイル: kzsPhysXFramework.cpp プロジェクト: kzs-sgw/GLSL
// **initPx_CreateScene**
void kzsPhysXFramework::initPx_CreateScene( PxVec3 _gravity )
{
	printf( "creating the scene\n" );
	// create the scene
	PxSceneDesc sceneDesc( gPhysicsSDK->getTolerancesScale() );
	sceneDesc.gravity = _gravity;

	if ( !sceneDesc.cpuDispatcher )
	{
		PxDefaultCpuDispatcher* mCpuDispatcher = PxDefaultCpuDispatcherCreate(1);
		sceneDesc.cpuDispatcher = mCpuDispatcher;
	}
	
	if ( !sceneDesc.filterShader )
	{
		sceneDesc.filterShader = gDefaultFilterShader;
	}
	
	gScene = gPhysicsSDK->createScene( sceneDesc );
	if ( !gScene ) cerr << "createScene failed!" << endl;
}
コード例 #8
0
ファイル: PhysXDevice.cpp プロジェクト: SeungMinChoi/Jaraffe
void JF::JFCPhysXDevice::DeviceInit()
{
	// 1) 
	m_Foundation = PxCreateFoundation(PX_PHYSICS_VERSION, m_Allocator, m_ErrorCallback);

	// 2) 프로파일러 생성
	PxProfileZoneManager* profileZoneManager = &PxProfileZoneManager::createProfileZoneManager(m_Foundation);
	m_Physics = PxCreatePhysics(PX_PHYSICS_VERSION, *m_Foundation, PxTolerancesScale(), true, profileZoneManager);

	// 3) 그래픽 디버거 연결.
	if (m_Physics->getPvdConnectionManager())
	{
		m_Physics->getVisualDebugger()->setVisualizeConstraints(true);
		m_Physics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_CONTACTS, true);
		m_Physics->getVisualDebugger()->setVisualDebuggerFlag(PxVisualDebuggerFlag::eTRANSMIT_SCENEQUERIES, true);
		m_Connection = PxVisualDebuggerExt::createConnection(m_Physics->getPvdConnectionManager(), "127.0.0.1", 5425, 10);
	}

	// 4)
	m_Dispatcher = PxDefaultCpuDispatcherCreate(2);
}
コード例 #9
0
		/**
		 * Private method which is used to initialize engine physics scene. Create scene based on scene descriptor,
		 * set gravity, inner obejcts like cpu dispatcher, filter shader and simulation event callback object.
		 */
		void PhysicsManager::initializeScene()
		{
			PxSceneDesc sceneDesc(physicsSDK->getTolerancesScale());
			sceneDesc.gravity = PxVec3(0.0f, -9.8f, 0.0f);
			if(!sceneDesc.cpuDispatcher)
			{
				PxDefaultCpuDispatcher* cpuDispatcher = PxDefaultCpuDispatcherCreate(1);
				if(!cpuDispatcher)
					Logger::getInstance()->saveLog(Log<string>("PxDefaultCpuDispatcherCreate creation error occurred!"));		
				sceneDesc.cpuDispatcher = cpuDispatcher;
			}

			if(!sceneDesc.filterShader)
				sceneDesc.filterShader = defaultFilterShader;

			scene = physicsSDK->createScene(sceneDesc);
		
			if(!scene)
				Logger::getInstance()->saveLog(Log<string>("Scene creation error occurred!"));
			
			scene->setVisualizationParameter(PxVisualizationParameter::eSCALE,1.0);
			scene->setVisualizationParameter(PxVisualizationParameter::eCOLLISION_SHAPES,1.0f);
			scene->setSimulationEventCallback(collisionHandler);
		}
コード例 #10
0
ファイル: EnginePhysics.cpp プロジェクト: thomhughes/Awe
void InitializePhysX(vector<PhysXObject*>* &cubeList)
{
    allActors = new vector<PhysXObject*>;

    PxFoundation* foundation = PxCreateFoundation(PX_PHYSICS_VERSION,
                               gDefaultAllocatorCallback, gDefaultErrorCallback);
    gPhysicsSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *foundation, PxTolerancesScale());

    if(gPhysicsSDK == NULL)
    {
        exit(1);
    }

    PxInitExtensions(*gPhysicsSDK);

    PxSceneDesc sceneDesc(gPhysicsSDK->getTolerancesScale());

    sceneDesc.gravity=PxVec3(0.0f, -9.8f, 0.0f);

    if(!sceneDesc.cpuDispatcher)
    {
        PxDefaultCpuDispatcher* mCpuDispatcher = PxDefaultCpuDispatcherCreate(3);

        sceneDesc.cpuDispatcher = mCpuDispatcher;
    }

    if(!sceneDesc.filterShader)
        sceneDesc.filterShader = gDefaultFilterShader;

    gScene = gPhysicsSDK->createScene(sceneDesc);

    gScene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1.0);
    gScene->setVisualizationParameter(PxVisualizationParameter::eCOLLISION_SHAPES, 1.0f);


    //1) Create Planes
    PxMaterial* mMaterial = gPhysicsSDK->createMaterial(0.5, 0.5, 0.5);

    for(int i = 0; i < 1; i++)
    {
        PhysXObject* plane = new PhysXObject;
        plane->actor = gPhysicsSDK->createRigidStatic(planePoses[i]);

        PxShape* shape = plane->actor->createShape(PxPlaneGeometry(), *mMaterial);

        gScene->addActor(*(plane->actor));
        allActors->push_back(plane);
        planes.push_back(plane);
    }

    //2) Create Planets
    PxReal planetDensity = 1.0f;
    PxVec3 planetDimensions(2,2,2);
    PxBoxGeometry planetGeom(planetDimensions);
    PxTransform planetTransform;

    for(int i = 0; i < PLANET_NUM; i++)
    {
        planetTransform = planetTransforms[i];
        PhysXObject* planet = new PhysXObject;
        planet->actor = PxCreateStatic(*gPhysicsSDK, planetTransform, planetGeom, *mMaterial);

        EnableGravity(planet->actor);

        gScene->addActor(*(planet->actor));
        allActors->push_back(planet);
        planets.push_back(planet);

        //HACK:
        /* Create the joint handlers for distance limiting
        /* We need to do this because a distance joint attached to an actor
        /* seems to void collisions between those two actors (i.e. "phases through")
        /* So we make another actor in the same position to hold the position

        PhysXObject* newHandle = new PhysXObject;
        newHandle->actor = PxCreateStatic(*gPhysicsSDK, tran, boxgeom, *mMaterial);

        gScene->addActor(*(newHandle->actor));
        planetJointHandles.push_back(newHandle);
        //We also don't need to worry about drawing the joints, for obvious reasons
        */
    }

    //3) Create Cubes
    PxReal density = 1.0f;
    PxTransform transform(PxVec3(0.0f, 0.0f, 0.0f), PxQuat::createIdentity());
    PxVec3 dimensions(0.5, 0.5, 0.5);
    PxBoxGeometry geometry(dimensions);

    for(int i = 0; i < BLOCK_NUM; i++)
    {
        srand((time(NULL) * i) + time(NULL));

        transform.p = PxVec3((float)((rand() % (2 * PLANET_HEIGHT)) - PLANET_HEIGHT),
                             (float)((rand() % (2 * PLANET_HEIGHT)) - PLANET_HEIGHT),
                             (float)((rand() % (2 * PLANET_HEIGHT)) - PLANET_HEIGHT));

        PhysXObject* cube = new PhysXObject;

        cube->actor = PxCreateDynamic(*gPhysicsSDK, transform, geometry, *mMaterial, density);

        //Create Distance Joints between planets here
        //Not included for run time optimizations
        //End creating distance joints

        //Create D6 Joints between planets here
        //Not included for run time optimizations
        //End creating distance joints

        cube->actor->isRigidDynamic()->setAngularDamping(0.75);
        cube->actor->isRigidDynamic()->setLinearVelocity(PxVec3(0,0,0));

        gScene->addActor(*(cube->actor));
        allActors->push_back(cube);
        boxes.push_back(cube);
    }

    cubeList = allActors;
}
コード例 #11
0
ファイル: gameWorld.cpp プロジェクト: abucraft/opengl-balls
void GameWorld::init()
{
	gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
	if (!gFoundation) {
		printf("PxCreateFoundation failed!");
	}
	gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(), true);
	if (!PxInitExtensions(*gPhysics)) {
		printf("init error pxinit\n");
	}
	gCooking = PxCreateCooking(PX_PHYSICS_VERSION, *gFoundation, PxCookingParams(gPhysics->getTolerancesScale()));
	if (!gCooking) {
		printf("PxCreateCooking failed!\n");
	}
	PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
	sceneDesc.gravity = PxVec3(0.0f, -98.0f, 0.0f);
	gDispatcher = PxDefaultCpuDispatcherCreate(2);
	sceneDesc.cpuDispatcher = gDispatcher;
	sceneDesc.filterShader = PxDefaultSimulationFilterShader;
	gScene = gPhysics->createScene(sceneDesc);
	gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f);
	PxRigidStatic* groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, 0, 1, 400), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, 0, -1, 400), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(1, 0, 0, 280), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(-1, 0, 0, 280), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, -1, 0, 600), *gMaterial);
	gScene->addActor(*groundPlane);
	groundPlane = PxCreatePlane(*gPhysics, PxPlane(0, 1, 0, -1), *gMaterial);
	gScene->addActor(*groundPlane);
	gGround.loadFromObj(GROUND_FILE);
	gGround.cookingMesh(*gPhysics, *gCooking);
	gGround.createActor(*gMaterial, *gPhysics);
	gScene->addActor(*(gGround.actor));

	//包围盒
	box.loadFromObj(BOX_FILE);

	//初始化飞球
	pxFlyBall = new PxFlyBall(Color4f(1.0, 200 / 255.0, 0), 5.0);
	Material mtl;
	PerlinImage perlinYellow = createPerlinLightYelloImage(40, 40, 6, 1.8);
	PerlinTexture(perlinYellow, mtl.kd_texid);
	mtl.ka = Color4f(1, 1, 1, 1);
	mtl.kd = Color4f(1, 1, 1, 1);
	mtl.ks = Color4f(1, 1, 1, 1);
	pxFlyBall->mtl = mtl;
	pxFlyBall->createPxBall(*gPhysics, PxTransform(PxVec3(rand() % 500 - 250, 100, rand() % 700 - 350)), *gMaterial);
	pxFlyBall->pxActor->setAngularDamping(0.5);
	perlinYellow.clear();
	gScene->addActor(*(pxFlyBall->pxActor));

	//初始化白球
	pxControlBall = new PxControlBall(Color4f(1.0, 1.0, 1.0), 5.0);
	PerlinImage perlinGray = createPerlinGrayImage(40, 40, 6, 1.8);
	PerlinTexture(perlinGray, mtl.kd_texid);
	mtl.ka = Color4f(1, 1, 1, 1);
	mtl.kd = Color4f(1, 1, 1, 1);
	mtl.ks = Color4f(0, 0, 0, 0);
	pxControlBall->mtl = mtl;
	pxControlBall->createPxBall(*gPhysics, PxTransform(PxVec3(0, 50, 0)), *gMaterial);
	pxControlBall->pxActor->setAngularDamping(0.5);
	perlinGray.clear();
	gScene->addActor(*(pxControlBall->pxActor));
	
	GLfloat light1PosType[] = { -5.0,1.0,5.0,0.0 };
	GLfloat whiteColor[] = { 1.0,1.0,1.0,1.0 };
	GLfloat darkColor[] = { 0.4,0.4,0.4,1 };
	GLfloat specColor[] = { 1,1,1,1 };
	GLfloat lightColor[] = { 1,1,1,1 };
	GLfloat globalAmbient[] = { 0.2,0.2,0.2,1.0 };
	glLightModelfv(GL_LIGHT_MODEL_AMBIENT, globalAmbient);
	glLightfv(GL_LIGHT1, GL_AMBIENT, darkColor);
	glLightfv(GL_LIGHT1, GL_DIFFUSE, lightColor);
	glLightfv(GL_LIGHT1, GL_SPECULAR, specColor);
	glLightfv(GL_LIGHT1, GL_POSITION, light1PosType);
}
コード例 #12
0
ファイル: scene.cpp プロジェクト: crucifix35/base-pro-edition
void Scene::initializePhysics(void)
{
    // database record for scene location
    database::LocationInfo* locationInfo = database::LocationInfo::getRecord( _location->getDatabaseId() );

    // find collision geometry
    engine::IClump* collisionClump = NULL;
    callback::ClumpL clumpL;
    _extrasAsset->forAllClumps( callback::enumerateClumps, &clumpL );
    for( callback::ClumpI clumpI=clumpL.begin(); clumpI!=clumpL.end(); clumpI++ )
    {
        if( strcmp( (*clumpI)->getName(), "CollisionGeometry" ) == 0 )
        {
            collisionClump = (*clumpI);
            break;
        }
    }
    assert( collisionClump != NULL );
    collisionClump->getFrame()->translate( Vector3f( 0,0,0 ) );
    collisionClump->getFrame()->getLTM();

    // determine physics scene bounds by collision geometry
    callback::AtomicL atomicL;
    collisionClump->forAllAtomics( callback::enumerateAtomics, &atomicL );
    assert( atomicL.size() == 1 );
    _collisionGeometry = *atomicL.begin();
    Vector3f sceneInf = _collisionGeometry->getAABBInf();
    Vector3f sceneSup = _collisionGeometry->getAABBSup();
    _phSceneBounds = PxBounds3 (PxVec3(sceneInf[0], sceneInf[1], sceneInf[2]),
                                PxVec3(sceneSup[0], sceneSup[1], sceneSup[2]));

    // determine limits of scene
    _phSceneLimits.maxNbActors = locationInfo->physicsLimits.numActors;
    _phSceneLimits.maxNbBodies = locationInfo->physicsLimits.numBodies;
    //_phSceneLimits.maxNbJoints = locationInfo->physicsLimits.numJoints;
    _phSceneLimits.maxNbDynamicShapes = locationInfo->physicsLimits.numDynamicShapes;
    _phSceneLimits.maxNbStaticShapes  = locationInfo->physicsLimits.numStaticShapes;

    // initialize physics scene
    PxSceneDesc _phSceneDesc(PxGetPhysics().getTolerancesScale());
    _phSceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
    _phSceneDesc.broadPhaseType = PxBroadPhaseType::eSAP;

    //PHYSX3 fix collision filters
    //_phSceneDesc.userNotify = NULL;
    //_phSceneDesc.userTriggerReport = this;
    //_phSceneDesc.userContactReport = this;
    //_phSceneDesc.maxTimestep = simulationStepTime;
    //_phSceneDesc.maxIter = 1;
    //_phSceneDesc.timeStepMethod = NX_TIMESTEP_VARIABLE;
    //_phSceneDesc.groundPlane = false;
    //_phSceneDesc.boundsPlanes = false;
    //_phSceneDesc.collisionDetection = true;
    _phSceneDesc.userData = this;

    // create scene
    //mNbThreads = PxMax(PxI32(shdfnd::Thread::getNbPhysicalCores())-1, 0);
    //#ifdef PX_PS3
    //	mNbThreads = 1; // known issue, 0 worker threads and SPU batched query can deadlock.
    //#endif
    //PHYSX3
    mNbThreads = 1;
    if(!_phSceneDesc.cpuDispatcher) {
        mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
        //PHYSX3
        //if(!mCpuDispatcher)
        //	fatalError("PxDefaultCpuDispatcherCreate failed!");
        _phSceneDesc.cpuDispatcher    = mCpuDispatcher;
    }
    if(!_phSceneDesc.filterShader)
        _phSceneDesc.filterShader    = gDefaultFilterShader;

#ifdef PX_WINDOWS
    if(!_phSceneDesc.gpuDispatcher && mCudaContextManager) {
        _phSceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();
    }
#endif
    _phScene = PxGetPhysics().createScene(_phSceneDesc);
    assert( _phScene );

    // post-creation scene settings
    _phScene->setVisualizationCullingBox(_phSceneBounds);
    _phScene->setLimits(_phSceneLimits);

    // default material
    PxMaterial* defaultMaterial = PxGetPhysics().createMaterial(0.25f, 0.25f, 0.5f);

    // add ground plane
    PxRigidStatic* groundPlane = PxCreatePlane(PxGetPhysics(), PxPlane(0,1,0,0), *defaultMaterial);
    _phScene->addActor(*groundPlane);

    // fixed flesh material
    _phFleshMaterial = PxGetPhysics().createMaterial(0.75f, 0.75f, 0.25f);
    _phFleshMaterial->setFrictionCombineMode(PxCombineMode::eMAX);
    _phFleshMaterial->setRestitutionCombineMode(PxCombineMode::eMULTIPLY);
    assert( _phFleshMaterial );

    // moving flesh material
    _phMovingFleshMaterial = PxGetPhysics().createMaterial(0.25f, 0.25f, 0.125f);
    _phMovingFleshMaterial->setFrictionCombineMode(PxCombineMode::eMAX);
    _phMovingFleshMaterial->setRestitutionCombineMode(PxCombineMode::eMULTIPLY);
    assert( _phMovingFleshMaterial );

    // cloth material
    _phClothMaterial = PxGetPhysics().createMaterial(0.995f, 0.995f, 0.05f);
    _phClothMaterial->setFrictionCombineMode(PxCombineMode::eMAX);
    _phClothMaterial->setRestitutionCombineMode(PxCombineMode::eMULTIPLY);
    assert( _phClothMaterial );

    // build terrain mesh data
    Matrix4f collisionGeometryLTM = _collisionGeometry->getFrame()->getLTM();
    Vector3f worldVertex;
    engine::Mesh* mesh = _collisionGeometry->getGeometry()->createMesh();
    _phTerrainVerts = new PxVec3[mesh->numVertices];
    _phTerrainTriangles = new PxU32[3*mesh->numTriangles];
    //PHYSX3
    //_phTerrainMaterials = new NxMaterialIndex[mesh->numTriangles];
    unsigned int i;
    for( i=0; i<mesh->numVertices; i++ )
    {
        worldVertex = Gameplay::iEngine->transformCoord( mesh->vertices[i], collisionGeometryLTM );
        _phTerrainVerts[i] = wrap( worldVertex );
    }
    for( i=0; i<mesh->numTriangles; i++ )
    {
        _phTerrainTriangles[i*3+0] = mesh->triangles[i].vertexId[0];
        _phTerrainTriangles[i*3+1] = mesh->triangles[i].vertexId[1];
        _phTerrainTriangles[i*3+2] = mesh->triangles[i].vertexId[2];
        //PHYSX3
        //_phTerrainMaterials[i] = 0;
    }

    // initialize terrain descriptor
    _phTerrainDesc.points.count = mesh->numVertices;
    _phTerrainDesc.points.data = _phTerrainVerts;
    _phTerrainDesc.points.stride = sizeof(PxVec3);
    _phTerrainDesc.triangles.count = mesh->numTriangles;
    _phTerrainDesc.triangles.data = _phTerrainTriangles;
    _phTerrainDesc.triangles.stride = 3 * sizeof(PxU32);

    //PHYSX3
    //_phTerrainDesc.materialIndexStride = sizeof( PxMaterialIndex );
    //_phTerrainDesc.materialIndices = _phTerrainMaterials;
    //_phTerrainDesc.heightFieldVerticalAxis = NX_NOT_HEIGHTFIELD;
    //_phTerrainDesc.heightFieldVerticalExtent = -1000;

    // cook terrain

    _phTerrainMesh = Gameplay::pxCooking->createTriangleMesh(_phTerrainDesc, PxGetPhysics().getPhysicsInsertionCallback());

    assert (_phTerrainMesh);

    _phTerrain = PxGetPhysics().createRigidStatic(PxTransform(PxVec3(0.0f, 1.0f, 0.0f), PxQuat(PxHalfPi / 60.0f, PxVec3(0.0f, 1.0f, 0.0f))));

    assert (_phTerrain);

    PxTriangleMeshGeometry triGeom(_phTerrainMesh);
    PxShape* triangleMeshShape = _phTerrain->createShape(triGeom, *defaultMaterial);
    assert (triangleMeshShape);

    _phScene->addActor(*_phTerrain);

    //PHYSX3
    // retrieve terrain shape
    _phTerrain->getShapes(&_phTerrainShape, 1);
    assert( _phTerrainShape );

    Gameplay::iEngine->releaseMesh( mesh );
}