Example #1
0
    //PxRigidDynamic* createDynamic(const PxTransform& t, const PxGeometry& geometry, const PxVec3& velocity=PxVec3(0)){
    PxRigidDynamicPtr createDynamic(PxTransform t, PxGeometry.Ref geometry, PxVec3 velocity)
    {
        //PxRigidDynamic* dynamic = PxCreateDynamic(*gPhysics, t, geometry, *gMaterial, 10.0f);
        //dynamic->setAngularDamping(0.5f);
        //dynamic->setLinearVelocity(velocity);
        //gScene->addActor(*dynamic);
        //return dynamic;
        PxRigidDynamicPtr dynamic = PxCreateDynamic(gPhysics, t, geometry, gMaterial, 10);

        dynamic.setAngularDamping(.5f);
        dynamic.setLinearVelocity(velocity);
        gScene.addActor(dynamic);
        return(dynamic);
    }
Example #2
0
    //void createStack(const PxTransform& t, PxU32 size, PxReal halfExtent){
    void createStack(PxTransform t, uint size, float halfExtent)
    {
        //PxShape* shape = gPhysics->createShape(PxBoxGeometry(halfExtent, halfExtent, halfExtent), *gMaterial);
        PxShapePtr shape = gPhysics.createShape(new PxBoxGeometry(halfExtent, halfExtent, halfExtent), gMaterial);

        //for(PxU32 i=0; i<size;i++){
        // for(PxU32 j=0;j<size-i;j++){
        for (int i = 0; i < size; i++)
        {
            for (int j = 0; j < size - i; j++)
            {
                //PxTransform localTm(PxVec3(PxReal(j*2) - PxReal(size-i), PxReal(i*2+1), 0) * halfExtent);
                //PxRigidDynamic* body = gPhysics->createRigidDynamic(t.transform(localTm));
                //body->attachShape(*shape);
                //PxRigidBodyExt::updateMassAndInertia(*body, 10.0f);
                //gScene->addActor(*body);
                PxTransform       localTm = new PxTransform(new PxVec3(((j * 2) - (size - i)) * halfExtent, (i * 2 + 1) * halfExtent, 0));
                PxRigidDynamicPtr body    = gPhysics.createRigidDynamic(t.transform(localTm));
                body.attachShape(shape);
                PxRigidBodyExt.updateMassAndInertia(body, 10);
                gScene.addActor(body);
            }
        }
        //shape->release();
        shape.release();
    }
Example #3
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);
        }
    }
Example #4
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));
        }
    }