示例#1
0
    //void createPhysicsAndScene()
    void createPhysicsAndScene()
    {
        //gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
        gFoundation = SharpPhysX.CreateFoundation(gErrorCallback, PX_PHYSICS_VERSION);

        //gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(),true,gPvd);
        gPhysics = PxPhysics.PxCreatePhysics(PX_PHYSICS_VERSION, gFoundation, PxTolerancesScale.Default());

        //gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f);
        gMaterial = gPhysics.createMaterial(.5f, .5f, .6f);

        //PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
        //sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
        var sceneDesc = PxSceneDescPtr.New(PxTolerancesScale.Default());

        sceneDesc.gravity = new PxVec3(0, -9.81f, 0);

        //PxU32 numCores = SnippetUtils::getNbPhysicalCores();
        //gDispatcher = PxDefaultCpuDispatcherCreate(numCores == 0 ? 0 : numCores - 1);
        //sceneDesc.cpuDispatcher	= gDispatcher;
        //sceneDesc.filterShader	= PxDefaultSimulationFilterShader;
        uint numCores = 4; //TODO

        gDispatcher             = PxDefaultCpuDispatcherCreate(numCores);
        sceneDesc.cpuDispatcher = gDispatcher;
        sceneDesc.filterShader  = PxDefaultSimulationFilterShader;

        //gScene = gPhysics->createScene(sceneDesc);
        gScene = gPhysics.createScene(sceneDesc);

        //PxRigidStatic* groundPlane = PxCreatePlane(*gPhysics, PxPlane(0,1,0,0), *gMaterial);
        //gScene->addActor(*groundPlane);
        var groundPlane = PxCreatePlane(gPhysics, new PxPlane(0, 1, 0, 0), gMaterial);

        gScene.addActor(groundPlane);

        //for(PxU32 i=0;i<5;i++)
        //createStack(PxTransform(PxVec3(0,0,i*10.0f)), 10, 2.0f);
        for (int i = 0; i < 5; i++)
        {
            createStack(new PxTransform(new PxVec3(0, 0, i * 10)), 10, 2);
        }
    }
示例#2
0
    //void initPhysics(bool interactive){
    void initPhysics(bool interactive)
    {
        //gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, gErrorCallback);
        gFoundation = SharpPhysX.CreateFoundation(gErrorCallback, PX_PHYSICS_VERSION);

        //gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(),true,gPvd);
        gPhysics = PxPhysics.PxCreatePhysics(PX_PHYSICS_VERSION, gFoundation, PxTolerancesScale.Default());

        //PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
        //sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
        //gDispatcher = PxDefaultCpuDispatcherCreate(2);
        //sceneDesc.cpuDispatcher = gDispatcher;
        //sceneDesc.filterShader = PxDefaultSimulationFilterShader;
        //gScene = gPhysics->createScene(sceneDesc);
        var sceneDesc = PxSceneDescPtr.New(PxTolerancesScale.Default());

        sceneDesc.gravity       = new PxVec3(0, -9.81f, 0);
        gDispatcher             = PxDefaultCpuDispatcherCreate(2);
        sceneDesc.cpuDispatcher = gDispatcher;
        sceneDesc.filterShader  = PxDefaultSimulationFilterShader;
        gScene = gPhysics.createScene(sceneDesc);

        //gMaterial = gPhysics->createMaterial(0.5f, 0.5f, 0.6f);
        gMaterial = gPhysics.createMaterial(.5f, .5f, .6f);

        //PxRigidStatic* groundPlane = PxCreatePlane(*gPhysics, PxPlane(0,1,0,0), *gMaterial);
        //gScene->addActor(*groundPlane);
        var groundPlane = PxCreatePlane(gPhysics, new PxPlane(0, 1, 0, 0), gMaterial);

        gScene.addActor(groundPlane);

        //for(PxU32 i=0;i<5;i++)
        // createStack(PxTransform(PxVec3(0,0,stackZ-=10.0f)), 10, 2.0f);
//        for (int i = 0; i < 5; i++)
//            createStack(new PxTransform(new PxVec3(0, 0, stackZ -= 10)), 10, 2);

        //if(!interactive)
        // createDynamic(PxTransform(PxVec3(0,40,100)), PxSphereGeometry(10), PxVec3(0,-50,-100));
        if (!interactive)
        {
            DEBUG = createDynamic(new PxTransform(new PxVec3(0, 40, 100)), new PxSphereGeometry(10), new PxVec3(0, -50, -100));
        }
    }