// Create a scene
NxSceneDesc sceneDesc;
sceneDesc.simType = NX_SIMULATION_HW;
sceneDesc.gravity = NxVec3(0.0f, -9.81f, 0.0f);
_scene = _sdk->createScene(sceneDesc);
if(_scene == NULL)
{
sceneDesc.simType = NX_SIMULATION_SW;
_scene = _sdk->createScene(sceneDesc);
if (_scene==NULL)
fatalerr("createScene failed!");
}
NxSceneDesc sceneDesc;
sceneDesc.simType = NX_SIMULATION_HW;
sceneDesc.gravity = NxVec3(0.0f, -9.81f, 0.0f);
_scene = _sdk->createScene(sceneDesc);
if(_scene == NULL)
{
sceneDesc.simType = NX_SIMULATION_SW;
_scene = _sdk->createScene(sceneDesc);
if (_scene==NULL)
fatalerr("createScene failed!");
}
在上面的代码中,第一次创建NxScene总是失败,返回NULL。
如果使用了NxPhysicsSDKDesc参数来创建PhysicsSDK,需要在NxPhysicsSDKDesc中设置GPUHeapSize关闭flag NX_SDKF_NO_HARDWARE(2011.6.27更正)。
// Initialize PhysicsSDK
NxPhysicsSDKDesc desc;
desc.gpuHeapSize = 8; //!!!重要
desc.flags &= ~NX_SDKF_NO_HARDWARE; // 这才是真的重要!!2011.6.27
NxSDKCreateError errorCode = NXCE_NO_ERROR;
if (!_errstream)
_errstream = new nxErrorStreamDefault();
_sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, _allocator, _errstream, desc, &errorCode);
if(_sdk == NULL)
fatalerr("NxCreatePhysicsSDK failed!");
NxPhysicsSDKDesc desc;
desc.flags &= ~NX_SDKF_NO_HARDWARE; // 这才是真的重要!!2011.6.27
NxSDKCreateError errorCode = NXCE_NO_ERROR;
if (!_errstream)
_errstream = new nxErrorStreamDefault();
_sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION, _allocator, _errstream, desc, &errorCode);
if(_sdk == NULL)
fatalerr("NxCreatePhysicsSDK failed!");
_sdk->setParameter(NX_SKIN_WIDTH, 0.05f);
也可以直接调用无NxPhysicsSDKDesc参数的create方法_sdk = NxCreatePhysicsSDK(NX_PHYSICS_SDK_VERSION). 直接调用无SDKDesc参数的方法创建SDK,仍然不可以创建硬件加速的NxScene。因为默认的SDKDesc的NX_SDKF_NO_HARDWARE标志是打开的,需要将其关闭,才能创建硬件加速的NxScene(2011.6.27)。默认SDKDesc已经设置了gpuHeapSize,默认好像是15是32,单位是兆字节megabyte。文档中说明如下。
NxU32 NxPhysicsSDKDesc::gpuHeapSize
Sets the amount of GPU memory which will be reserved for the SDK.
The valid value must be power of 2. Unit is megabyte. Default value is 32 MB.