Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Categories
- All Discussions1,524
- General534
- Graphics109
- GPU Computing419
- Mobile141
- Pro Graphics163
- Tools158
In this Discussion
- ZokenSamurai February 12
Tags in this Discussion
- physx 272
Errors I Can't Figure Out With PhysX Sample Project
-
Code:
[code]
01|#include
02|#include
03|#define _DEBUG
04|#define PX_WINDOWS
05|#include
06|#include
07|
08|class PxDefaultErrorCallback : public PxErrorCallback
09|{
10|public:
11| PxDefaultErrorCallback();
12| ~PxDefaultErrorCallback();
13|
14| virtual void reportError(PxErrorCode::Enum code, const char* message, const char* 15|file, int line);
16|};
17|void PxDefaultErrorCallback::reportError(PxErrorCode::Enum e, const char* message, const char* 18|file, int line)
{
const char* errorCode = NULL;
switch (e)
{
case PxErrorCode::eINVALID_PARAMETER:
errorCode = "invalid parameter";
break;
case PxErrorCode::eINVALID_OPERATION:
errorCode = "invalid operation";
break;
case PxErrorCode::eOUT_OF_MEMORY:
errorCode = "out of memory";
break;
case PxErrorCode::eDEBUG_INFO:
errorCode = "info";
break;
case PxErrorCode::eDEBUG_WARNING:
errorCode = "warning";
break;
default:
errorCode = "unknown error";
break;
}
printf("%s (%d) :", file, line);
printf("%s", errorCode);
printf(" : %s\n", message);
}
class PxDefaultAllocator : public PxAllocatorCallback
{
void* allocate(size_t size, const char*, const char*, int)
{
return _aligned_malloc(size, 16);
}
void deallocate(void* ptr)
{
_aligned_free(ptr);
}
};
bool recordMemoryAllocations = true;
static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;
mSDK = PxCreatePhysics(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback, PxTolerancesScale(), recordMemoryAllocations );
if(!mSDK)
fatalError("PxCreatePhysics failed!");
if (!PxInitExtensions(*mSDK))
fatalError("PxInitExtensions failed!");
mCooking = PxCreateCooking(PX_PHYSICS_VERSION, &mSDK->getFoundation(), PxCookingParams());
if (!mCooking)
fatalError("PxCreateCooking failed!");
static PxDefaultSimulationFilterShader gDefaultFilterShader;
PxScene* mScene;
PxSceneDesc sceneDesc(mSDK->getTolerancesScale());
sceneDesc.gravity = PxVec3(0.0f, -9.81f, 0.0f);
customizeSceneDesc(sceneDesc);
if(!sceneDesc.cpuDispatcher)
{
mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
if(!mCpuDispatcher)
fatalError("PxDefaultCpuDispatcherCreate failed!");
sceneDesc.cpuDispatcher = mCpuDispatcher;
}
if(!sceneDesc.filterShader)
sceneDesc.filterShader = &gDefaultFilterShader;
#ifdef PX_WINDOWS
if(!sceneDesc.gpuDispatcher && mCudaContextManager)
{
sceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();
}
#endif
mScene = mSDK->createScene(sceneDesc);
if (!mScene)
fatalError("createScene failed!");
PxMaterial* mMaterial;
mMaterial = mSDK->createMaterial(0.5f, 0.5f, 0.1f); //static friction, dynamic friction, restitution
if(!mMaterial)
fatalError("createMaterial failed!");
PxReal d = 0.0f;
PxU32 axis = 1;
PxTransform pose;
if(axis == 0)
pose = PxTransform(PxVec3(d, 0.0f, 0.0f));
else if(axis == 1)
pose = PxTransform(PxVec3(0.0f, d, 0.0f),PxQuat(PxHalfPi, PxVec3(0.0f, 0.0f, 1.0f)));
else if(axis == 2)
pose = PxTransform(PxVec3(0.0f, 0.0f, d), PxQuat(-PxHalfPi, PxVec3(0.0f, 1.0f, 0.0f)));
PxRigidStatic* plane = mSDK->createRigidStatic(pose);
if (!plane)
fatalError("create plane failed!");
PxShape* shape = plane->createShape(PxPlaneGeometry(), *mMaterial);
if (!shape)
fatalError("create shape failed!");
mScene->addActor(*plane);
PxReal density = 1.0f;
PxTransform(PxVec3(0.0f, 5.0f, 0.0f), PxQuat::createIdentity());
PxVec3 dimensions(1.0f, 1.0f, 1.0f);
PxBoxGeometry geometry(dimensions);
PxRigidDynamic *actor = PxCreateDynamic(*mSDK, transform, geometry, *mMaterial, density);
if (!actor)
fatalError("create actor failed!");
mScene->addActor(*actor);
mAccumulator = 0.0f;
mStepSize = 1.0f / 60.0f;
virtual bool advance(PxReal dt)
{
mAccumulator += dt;
if(mAccumulator < mStepSize)
return false;
mAccumulator -= mStepSize;
mScene->simulate(mStepSize);
return true;
}
PxTransform newPose = PxShapeExt::getGlobalPose(*mPhysicsShape);
mScene->fetchResults(true);
mSDK->release();
[/code]
Errors I got:
-------------- Build: Debug in nvidiatest ---------------
Compiling: main.cpp
nvidiatest\main.cpp:9: error: expected class-name before '{' token
nvidiatest\main.cpp:14: error: 'PxErrorCode' has not been declared
nvidiatest\main.cpp:14: error: expected ',' or '...' before 'code'
nvidiatest\main.cpp:17: error: variable or field 'reportError' declared void
nvidiatest\main.cpp:17: error: 'PxErrorCode' has not been declared
nvidiatest\main.cpp:17: error: expected primary-expression before 'const'
nvidiatest\main.cpp:17: error: expected primary-expression before 'const'
nvidiatest\main.cpp:17: error: expected primary-expression before 'int'
Process terminated with status 1 (0 minutes, 1 seconds)
8 errors, 0 warnings -
1 Comment sorted by
-
I bet on a missing include. Unfortunately we cannot see your includes in your post...