0

I've uppgraded to PhysX 3.2 and have been struggling for days to have my test box moved by gravity but it simply won't to it.

I've followed the PhysX documentation but implemented it in my way. It's pretty much a default setup:

        physx::PxSceneDesc sceneDesc = physx::PxSceneDesc((physx::PxTolerancesScale()));
        sceneDesc.gravity = physx::PxVec3(0.0f, -9.8f, 0.0f);
        if(!sceneDesc.cpuDispatcher)
        {
            physx::PxDefaultCpuDispatcher* mCpuDispatcher = physx::PxDefaultCpuDispatcherCreate(4);
            if(!mCpuDispatcher)
                LOG("PxDefaultCpuDispatcherCreate failed!");
            sceneDesc.cpuDispatcher    = mCpuDispatcher;
        }
        if(!sceneDesc.filterShader)
            sceneDesc.filterShader    = &physx::PxDefaultSimulationFilterShader;


        physxScene = physMgr->getSDK()->createScene(sceneDesc);

Creating the dynamic actor:

                PxRigidDynamic* body = mPxSDK->createRigidDynamic(Convert::toPxTransform(transform));
                PxRigidBodyExt::updateMassAndInertia(*body, 1.0f);
                mPxScene->addActor(*body);

Add the box shape:

            PxBoxGeometry geometry = PxBoxGeometry(Convert::toPxVector3(size));
            if(geometry.isValid())
            {
                PxMaterial* material = api->createMaterial(0.5f, 0.5f, 0.1f);
                PxShape* shape = createShape(actor, geometry, material);
                                    PxRigidBodyExt::updateMassAndInertia(*body, 33.0f);
            }

Simulating the scene as:

    float elapsedTime = float((float)mTime.getElapsedTime() / 1000.0f);
    mAccumulator += elapsedTime;
    if(mAccumulator < mStepSize)
    {
        return;
    }
    else
    {
        mAccumulator -= mStepSize;
        mPxScene->simulate(mStepSize);
        mDynamicBodySys->updateGameObjectPositions();
        mPxScene->fetchResults(true);
        mTime.restart();

    }

When I look into the Visual Debugger I can see the box and the frame count increasing. But it's not moving. The actor's and the box shape seem to have the correct propeties. LinearVelocity is increasing in negative Y axis, its mass is 33 etc. But the pose is still zero/identity. What am I missing?

4

1 回答 1

0

解决了。错误是我自己的逻辑。有一个同步逻辑问题,PhysX 试图更新我的图形,同时我的定位逻辑告诉 PhysX 更新其先前的位置。所以它被卡住了,似乎从来没有被模拟过。

于 2012-03-20T09:44:14.160 回答