Thanks for all the replies. It helped, even when I could not make sense of them (give hint and google search terms etc...).
Plus i was probably looking for a complicated solution when a simple one works just fine.
Here is the solution I finally settled for. A vector to store bodies.
vector <PxRigidBody*> arrayofBodies;
PxTransform boxPos1(initpos,PxQuat(PxHalfPi, PxVec3(0.0f, 1.0f, 0.0f))); //Position and orientation(transform) for box actor
PxRigidDynamic *gBoxOri = NULL; //Instance of box actor
PxCapsuleGeometry sphereGeometry(radius,height); //Defining geometry for box actor
gBoxOri = PxCreateDynamic(*gPhysicsSDK, boxPos1, sphereGeometry, *material, 1.0f); //Creating rigid static actor
gScene->addActor(*gBoxOri); //Adding box actor to PhysX scene
arrayofBodies.push_back(gBoxOri); //vector is filled with bodies here...
for (PxU32 i=1; i<numberofblocks; i++)
{
PxTransform boxPos1(initpos+PxVec3(0.0f, 0.0f, 2*i*height/*2.0f*/),PxQuat(PxHalfPi, PxVec3(0.0f, 1.0f, 0.0f))); //Position and orientation(transform) for box actor
PxRigidDynamic *gBox = NULL; //Instance of box actor
PxCapsuleGeometry sphereGeometry(radius,height); //Defining geometry for box actor
gBox = PxCreateDynamic(*gPhysicsSDK, boxPos1, sphereGeometry, *material, 1.0f); //Creating rigid static actor
gScene->addActor(*gBox); //Adding box actor to PhysX scene
// adding some joint to the mix
//PxSphericalJoint* joint = PxSphericalJointCreate(*gPhysicsSDK, gBoxOri, PxTransform(-offset), gBox, PxTransform(offset));
//PxSphericalJoint* joint = PxSphericalJointCreate(*gPhysicsSDK, gBoxOri, PxTransform(offset0), gBox, PxTransform(offset1)); //uncomment to use spherical joints
PxD6Joint* joint = PxD6JointCreate(*gPhysicsSDK, gBoxOri, PxTransform(offset0), gBox, PxTransform(offset1));
//add some limits to the joint
//joint->setLimitCone(PxJointLimitCone(0.00000001f,0.00000001f,0.1f));
//joint->setSphericalJointFlag(PxSphericalJointFlag::eLIMIT_ENABLED,true);
joint->setSwingLimit(PxJointLimitCone(1.57f,1.57f,0.00000001f));
joint->setConstraintFlag(PxConstraintFlag::eVISUALIZATION, true);
joint->setMotion(PxD6Axis::eTWIST, PxD6Motion::eLOCKED);
joint->setMotion(PxD6Axis::eSWING1, PxD6Motion::eLIMITED);
joint->setMotion(PxD6Axis::eSWING2, PxD6Motion::eLIMITED);
//joint->setMotion(PxD6Axis::eSWING1, PxD6Motion::eFREE); //free to rotate around y axis
//add the body to the array before renaming the original box...
arrayofBodies.push_back(gBox); //vector is filled with bodies here...
gBoxOri=gBox;
I can then run through the vector of bodies with ease.
void countActor(void)
{
//PxU32 nbActors = gScene->getNbActors(physx::PxActorTypeSelectionFlag::eRIGID_DYNAMIC);
//PxActor** actors = new PxActor*[nbActors];
//gScene->getActors(physx::PxActorTypeSelectionFlag::eRIGID_DYNAMIC,actors,nbActors);
int nbActors=arrayofBodies.size();
//arrayofBodies[1]->addForce(PxVec3(0,800,0),PxForceMode::eACCELERATION);
while(nbActors--)
{
int fx=rand()%50;
int fy=rand()%50;
int fz=rand()%50;
//cout<<fx<<"_"<<fy<<"_"<<fz<<"\n";
//arrayofBodies[nbActors];
arrayofBodies[nbActors]->addForce(PxVec3(fx,fy,fz),PxForceMode::eIMPULSE);
arrayofBodies[nbActors]->getLinearVelocity
}
}
Again, kudo to all.