Hello , I have problem.
I created vehicle according SnippetVehicle4W .
It’s works fine on drivable plane but when I’m trying to drive on terrain (using PxHeightFieldGeometry) vehicle falls into terrain.
If I set PxHeightFieldGeometry heightScale to 0.001 then car is not falling, but terrain with 0.001 heightscale value same as plane.
What’s the problem?
PxReal heightScale = 0.01f;
PxReal whScale = 2.0f;
//
if(FAILED(terrain.Initialize(L"newheight.bmp",pDevice,heightScale, whScale)))
{
return S_OK;
}
int gridX = terrain.GetDimX();
int gridY = terrain.GetDimY();
pose = PxTransform(PxVec3(-(gridX/2*whScale), 0.0f, -(gridX/2*whScale)), PxQuat::createIdentity());
PxHeightFieldSample *hSample = (PxHeightFieldSample*) HeapAlloc(pHeap,0,sizeof(PxHeightFieldSample)*gridX*gridY);
//
int index = 0;
for(int i=0; i<gridX; i++)
{
for(int j=0; j<gridY; j++)
{
hSample[i*gridX + j].height = terrain.GetHeightValueAtPoint(index);
hSample[i*gridX + j].setTessFlag();
hSample[i*gridX + j].materialIndex0=1;
hSample[i*gridX + j].materialIndex1=1;
index+=3;
}
}
//
PxHeightFieldDesc hDesc;
hDesc.format = PxHeightFieldFormat::eS16_TM;
hDesc.nbRows = gridX;
hDesc.nbColumns = gridY;
hDesc.samples.data = hSample;
hDesc.samples.stride = sizeof(PxHeightFieldSample);
//
PxHeightField *pHeighField = pPhysSDK->createHeightField(hDesc);
PxHeightFieldGeometry hGeom(pHeighField, PxMeshGeometryFlags(),heightScale, whScale,whScale);
PxRigidStatic *terrain = pPhysSDK->createRigidStatic(pose);
PxShape* hShape[1];
hShape[0] = terrain->createShape(hGeom,*material);
terrain->getShapes(hShape, 1);
PxFilterData simulationFilterData;
simulationFilterData.word0 = COLLISION_FLAG_GROUND;
simulationFilterData.word1 = COLLISION_FLAG_GROUND_AGAINST;
PxFilterData queryFilterData;
queryFilterData.word3 = (PxU32)DRIVABLE_SURFACE;
hShape[0]->setQueryFilterData(queryFilterData);
hShape[0]->setSimulationFilterData(simulationFilterData);
pScene->addActor(*terrain);
terrain size is 128x128