plfiorini
06-01-2009 06:16:54
I know this has been discussed in other threads but the other threads was not that helpful for me.
I almost got the result I wanted, here's the code:
The log says:
I tried changing the heightScale some times but still no luck. I also took a look in this thread viewtopic.php?p=49677 and the NxOgre code.
All seems ok, but when I create some crates in my application they always fall under the ground.
Here's the update code in case there is something wrong there:
Anyone with some PhysX experience had any luck?
I almost got the result I wanted, here's the code:
void PhysicsManager::registerTerrain(const ET::TerrainInfo& info)
{
// Set heightfield description
NxHeightFieldDesc desc;
desc.nbRows = info.getWidth();
desc.nbColumns = info.getHeight();
desc.convexEdgeThreshold = 0;
desc.thickness = -100;
// Print some terrain information
Ogre::LogManager::getSingleton().logMessage("[PhysicsManager] Terrain size " +
Ogre::StringConverter::toString(Ogre::Vector2(desc.nbRows, desc.nbColumns)));
Ogre::LogManager::getSingleton().logMessage("[PhysicsManager] Terrain extents " +
Ogre::StringConverter::toString(info.getExtents().getSize()));
Ogre::LogManager::getSingleton().logMessage("[PhysicsManager] Terrain scaling " +
Ogre::StringConverter::toString(info.getScaling()));
Ogre::LogManager::getSingleton().logMessage("[PhysicsManager] Terrain offset " +
Ogre::StringConverter::toString(info.getOffset()));
// Extent size
NxReal sizeX = info.getExtents().getSize().x;
NxReal sizeY = info.getExtents().getSize().y;
NxReal sizeZ = info.getExtents().getSize().z;
// Heightfield samples
desc.samples = new NxU32[desc.nbRows * desc.nbColumns];
desc.sampleStride = sizeof(NxU32);
// Set heightfield samples height
char* currentByte = (char*)desc.samples;
for (NxU32 row = 0; row < desc.nbRows; row++)
{
for (NxU32 column = 0; column < desc.nbColumns; column++)
{
NxHeightFieldSample* currentSample = (NxHeightFieldSample*)currentByte;
currentSample->height = info.at(row, column) * (2^15);
currentSample->materialIndex0 = 1;
currentSample->materialIndex1 = 1;
currentSample->tessFlag = 0;
currentByte += desc.sampleStride;
}
}
// Create heightfield
mHeightField = mPhysicsSDK->createHeightField(desc);
// Free heightfield samples because data has already been used
delete [] desc.samples;
// Terrain shape
NxHeightFieldShapeDesc shapeDesc;
shapeDesc.heightField = mHeightField;
shapeDesc.shapeFlags = NX_SF_FEATURE_INDICES;
if (gEnableDebugger)
shapeDesc.shapeFlags |= NX_SF_VISUALIZATION;
//shapeDesc.heightScale = sizeY / (2^15);
shapeDesc.heightScale = (sizeY * 0.5f) / (2^15);
shapeDesc.rowScale = sizeX / NxReal(desc.nbRows - 1);
shapeDesc.columnScale = sizeZ / NxReal(desc.nbColumns - 1);
shapeDesc.materialIndexHighBits = 0;
shapeDesc.holeMaterial = 3500;
//shapeDesc.localPose.t = NxVec3(info.getOffset().x, info.getOffset().y, info.getOffset().z);
Ogre::LogManager::getSingleton().logMessage("[PhysicsManager] Terrain shape: " +
Ogre::String("heightScale=") + Ogre::StringConverter::toString(shapeDesc.heightScale) + " " +
Ogre::String("rowScale=") + Ogre::StringConverter::toString(shapeDesc.rowScale) + " " +
Ogre::String("columnScale=") + Ogre::StringConverter::toString(shapeDesc.columnScale));
// Actor
NxActorDesc actorDesc;
actorDesc.shapes.pushBack(&shapeDesc);
actorDesc.density = 1.0f;
actorDesc.globalPose.t = NxVec3(info.getOffset().x, info.getOffset().y, info.getOffset().z);
mTerrainActor = mScene->createActor(actorDesc);
}
The log says:
07:13:23: [PhysicsManager] Terrain size 1025 1025
07:13:23: [PhysicsManager] Terrain extents 5000 1667 5000
07:13:23: [PhysicsManager] Terrain scaling 4.87805 1667 4.87805
07:13:23: [PhysicsManager] Terrain offset 0 0 0
07:13:23: [PhysicsManager] Terrain shape: heightScale=64.1154 rowScale=4.88281 columnScale=4.88281
I tried changing the heightScale some times but still no luck. I also took a look in this thread viewtopic.php?p=49677 and the NxOgre code.
All seems ok, but when I create some crates in my application they always fall under the ground.
Here's the update code in case there is something wrong there:
bool PhysicsManager::update(const Ogre::Real& elapsed)
{
mScene->simulate(elapsed);
mScene->flushStream();
mScene->fetchResults(NX_RIGID_BODY_FINISHED, true);
// TODO: Delete any actor that may have had request to release it from callbacks
// Move scene node associated to every actor
NxActor** actors = mScene->getActors();
const NxU32 nbActors = mScene->getNbActors();
for (NxU32 i = 0; i < nbActors; ++i)
{
NxActor* actor = actors[i];
Ogre::SceneNode* sceneNode = static_cast<Ogre::SceneNode*>(actor->userData);
if (sceneNode)
{
NxVec3 pos = actor->getGlobalPosition();
NxQuat ori = actor->getGlobalOrientationQuat();
sceneNode->setPosition(Ogre::Vector3(pos.x, pos.y, pos.z));
sceneNode->setOrientation(Ogre::Quaternion(ori.w, ori.x, ori.y, ori.z));
}
}
// Update controllers
if (mControllerManager)
mControllerManager->updateControllers();
return true;
}
Anyone with some PhysX experience had any luck?