Your code snippets are a little bit strange …
Okay: Here is an answer to your last post:
Sample Solution are here: (PhysX folder)\Samples\compiler\vc10win32public
For the extensions: (PhysX folder)\Source\compiler\vc10win32public
You dont need to call customizeSceneDesc(sceneDesc); - look into the code what happens there.
The PhysXGuide.chm shows alot of code and explains it- the samples uses a lot of the code.
You should study the samples - its a little bit smashed togehter, okay, but you could read the
important related code of it. I meant with “many samples” that there are the samples which
shows much things in PhysX - from PxController to Vehicles and Clothes … Callbacks, time stepping,
convertings, trigger shapes, convex mesh cooking - triangle mesh cooking… Almost every
important topics are covered there.
You should use precomplied header. Its really easy to handle it and its takes lesser time
to compile your project. There are other improvments - just read about them.
( And about header guards - use #pragma once )
I guess its only for testing purpose - but you should abstract each possible layer from a game -
and make different classes of it. (Example: The creation of plane doesnt have to do with
the physics - its created in another class (Level?) or in the main gamemanager)
Look at this - why should you place these important references on the stack instead of the heap?
Use them as pointer like this:
You should also use something like a Px::init() method for initialize the PhysX.
scale.mass = 1000.f;
scale.speed = 10.f;
scale.length = 1.f;
mFoundation = PxCreateFoundation(PX_PHYSICS_VERSION,*mAllocatorCallback,*mErrorCallback);
if(!mFoundation) printf("PxCreateFoundation failed!");
mProfileZoneManager = &PxProfileZoneManager::createProfileZoneManager(mFoundation);
if(!mProfileZoneManager) printf("PxProfileZoneManager::createProfileZoneManager failed!");
mSDK = PxCreatePhysics(PX_PHYSICS_VERSION, *mFoundation, scale, true, mProfileZoneManager);
if(!mSDK) printf("PxCreatePhysics failed!");
if(!PxInitExtensions(*mSDK)) printf("PxInitExtensions failed!");
mMaterial = mSDK->createMaterial(0.15f,0.15f,0.15f);
sceneDesc.gravity = PxVec3(0,-100.f,0);
CpuDispatcher = PxDefaultCpuDispatcherCreate(0);
if(!CpuDispatcher) printf("PxDefaultCpuDispatcherCreate failed!");
sceneDesc.cpuDispatcher = CpuDispatcher;
sceneDesc.filterShader = FilterShader;
sceneDesc.simulationEventCallback = mEventCallback;
if (!sceneDesc.filterShader) printf("FilterShader failed!");
mScene = getSDK()->createScene(sceneDesc);
mCooking = PxCreateCooking(PxVersion,*getFoundation(),PxCookingParams()); //Only when needed
if (!getCooking()) printf("Cooking failed!\n");
This is uncompleted - you need to modify it:
PxFilterFlags FilterShader(PxFilterObjectAttributes attributes0, PxFilterData filterData0,PxFilterObjectAttributes attributes1, PxFilterData filterData1,
PxPairFlags& pairFlags, const void* constantBlock, PxU32 constantBlockSize)
pairFlags = PxPairFlag::eCONTACT_DEFAULT | PxPairFlag::eTRIGGER_DEFAULT;
Okay… you need to modify the code above to your own code.
And always set uninitialized pointer to NULL (or when using C++ 11 to nullptr)
And when I see something like this:
I´m really worried if you really can program. Just type PxMaterial A = gPhysics …
I´m also confused about:
PX.gScene->addActor(aBoxActor); - You set gScene as pointer - you should access to it via ->
( You didnt declare PX as Px PX didnt you?! This should be a pointer like this: Px PX !)
Your timestep is wrong.
Use a accumulator for it (semi fixed timestep)
PxReal mAccumulator = 0.0f;
PxReal mStepSize = 0.01f; // You could use another StepSize here
void update() // Physic
mAccumulator += mGameManager->getDeltaTime();//timeSinceLastUpdate;
if (mAccumulator > 0.1f) mAccumulator = 0.1f; // Or other limit of the mAccumulator
while (mAccumulator >= mStepSize)
mAccumulator -= mStepSize;
I really dont know what you want to archiev with while(!gScene->fetchResults()) …
its … like … you didnt read the PhysXGuide and just smash some code together and hope for the best.
… No words needed here. Did you realize what you did here?
Hm there are other things too.
You really should study the examples to understand how you use them correctly.
(or to create /initialize PhysX related objects.)
All I said above was no offense to you!
I hope you think about your coding style and study the samples - and uses things to… (like pch)