Pages: [1]
Author Topic: PhysX on Code::Blocks  (Read 5549 times)
Posts: 1

View Profile
« on: February 12, 2012, 06:38:55 am »

I know these aren't the NVidia support forums, but I figured there might be one person here who can help me:

So I do not want to have to deal with a new compiler to do PhysX stuff. I use the GNU GCC compiler in MinGW on C::B.
I have successfully dealt with every problem except one.
I can not and do not want to use the __debugerror() function which is a visual C++ function with my compiler.

Here are the errors my compiler sends:

13|error: 'PxDefaultErrorCallback' does not name a type|
14|error: 'PxDefaultAllocator' does not name a type|
16|error: expected constructor, destructor, or type conversion before '=' token|
17|error: expected unqualified-id before 'if'|
21|error: expected class-name before '{' token|
|||In member function 'void* PxDefaultAllocator::allocate(size_t, const char*, const char*, int)':|
24|error: '_aligned_malloc' was not declared in this scope|
|||In member function 'void PxDefaultAllocator::deallocate(void*)':|
29|error: '_aligned_free' was not declared in this scope|
33|error: expected class-name before '{' token|
38|error: 'PxErrorCode' has not been declared|
38|error: expected ',' or '...' before 'code'|
41|error: variable or field 'reportError' declared void|
41|error: 'PxErrorCode' has not been declared|
41|error: expected primary-expression before 'const'|
41|error: expected primary-expression before 'const'|
41|error: expected primary-expression before 'int'|
||=== Build finished: 15 errors ===|

#include <windows.h>
#include <GL/glut.h>
#include <stdlib.h>
#define PX_WINDOWS
#define PX_CHECKED
#define NDEBUG
#include <PxPhysicsAPI.h>
#include <stdlib.h>
using namespace std;

bool recordMemoryAllocations = true;

static PxDefaultErrorCallback gDefaultErrorCallback;
static PxDefaultAllocator gDefaultAllocatorCallback;

mSDK = PxCreatePhysics(PX_PHYSICS_VERSION, gDefaultAllocatorCallback, gDefaultErrorCallback, PxTolerancesScale(), recordMemoryAllocations );
        fatalError("PxCreatePhysics failed!");
#include <malloc.h>
class PxDefaultAllocator : public PxAllocatorCallback
        void* allocate(size_t size, const char*, const char*, int)
                return _aligned_malloc(size, 16);

        void deallocate(void* ptr)
class PxDefaultErrorCallback : public PxErrorCallback

        virtual void reportError(PxErrorCode::Enum code, const char* message, const char* file, int line);

void PxDefaultErrorCallback::reportError(PxErrorCode::Enum e, const char* message, const char* file, int line)
        const char* errorCode = NULL;

        switch (e)
        case PxErrorCode::eINVALID_PARAMETER:
                errorCode = "invalid parameter";
        case PxErrorCode::eINVALID_OPERATION:
                errorCode = "invalid operation";
        case PxErrorCode::eOUT_OF_MEMORY:
                errorCode = "out of memory";
        case PxErrorCode::eDEBUG_INFO:
                errorCode = "info";
        case PxErrorCode::eDEBUG_WARNING:
                errorCode = "warning";
                errorCode = "unknown error";

        printf("%s (%d) :", file, line);
        printf("%s", errorCode);
        printf(" : %s\n", message);
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);

        mCpuDispatcher = PxDefaultCpuDispatcherCreate(mNbThreads);
                fatalError("PxDefaultCpuDispatcherCreate failed!");
        sceneDesc.cpuDispatcher = mCpuDispatcher;
        sceneDesc.filterShader  = &gDefaultFilterShader;

if(!sceneDesc.gpuDispatcher && mCudaContextManager)
        sceneDesc.gpuDispatcher = mCudaContextManager->getGpuDispatcher();
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
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!");
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!");
mAccumulator = 0.0f;
mStepSize = 1.0f / 60.0f;

virtual bool advance(PxReal dt)
        mAccumulator  += dt;
        if(mAccumulator < mStepSize)
                return false;

        mAccumulator -= mStepSize;

        return true;
PxTransform newPose = PxShapeExt::getGlobalPose(*mPhysicsShape);
Pages: [1]
Jump to: