gpt4 book ai didi

c++ - 如何在 Ogre3d 和 PhysX 中使用 16 位高度图

转载 作者:塔克拉玛干 更新时间:2023-11-03 07:37:30 32 4
gpt4 key购买 nike

我正在使用 Ogre3D 和 PhysX。

当我从 8 位高度图加载地形时,它在 Visual Debugger 上看起来很正常。

看第一张图: http://img44.imageshack.us/gal.php?g=44927650.jpg

但是当我将高度图保存为 16 位图像时,我得到了你在第二张图像上看到的内容。

这是代码,可以正常使用 8 位 PNG:

    mSceneMgr->setWorldGeometry("terrain.cfg" );
mTSM=static_cast<TerrainSceneManager*>(sceneMgr);

TerrainOptions mTerrainOptions = mTSM->getOptions();

//load heihgtmap
Image mImage;
mImage.load("isl_h_ph.png", ResourceGroupManager::getSingleton().getWorldResourceGroupName()); //load image

//write image buffer to pOrigSrc
const uchar* pOrigSrc = mImage.getData();
const uchar* pSrc;
// image size to mPageSize
size_t mPageSize = mTerrainOptions.pageSize;

NxActorDesc ActorDesc;

//set number of segments
heightFieldDesc = new NxHeightFieldDesc;
heightFieldDesc->nbColumns = mPageSize;
heightFieldDesc->nbRows = mPageSize;
heightFieldDesc->verticalExtent = -1000;
heightFieldDesc->convexEdgeThreshold = 0;

heightFieldDesc->samples = new NxU32[mPageSize*mPageSize]; //constructor for every sample?
heightFieldDesc->sampleStride = sizeof(NxU32); //some sample step = number of samples

pSrc = pOrigSrc;
char* currentByte = (char*)heightFieldDesc->samples; //current sample mb?
LogManager::getSingletonPtr()->logMessage("+++Heightmap---");
for (NxU32 row = 0; row < mPageSize; row++)
{
for (NxU32 column = 0; column < mPageSize; column++) //cycle around samples
{
pSrc = pOrigSrc + column*mPageSize +row;

//NxReal s = NxReal(row) / NxReal(mPageSize);
//NxReal t = NxReal(column) / NxReal(mPageSize);

NxI16 height = (NxI32)(*pSrc++);
NxU32 matrixOffset = (row % gMatrixSize) * gMatrixSize + (column % gMatrixSize);

//LogManager::getSingletonPtr()->logMessage(Ogre::StringConverter::toString(height));
NxHeightFieldSample* currentSample = (NxHeightFieldSample*)currentByte;
currentSample->height = height;
currentSample->materialIndex0 = gMatrix[matrixOffset][1];
currentSample->materialIndex1 = gMatrix[matrixOffset][2];
currentSample->tessFlag = gMatrix[matrixOffset][0];
currentByte += heightFieldDesc->sampleStride;
}
}

heightField = mScene->getPhysicsSDK().createHeightField(*heightFieldDesc);

NxHeightFieldShapeDesc heightFieldShapeDesc;
heightFieldShapeDesc.heightField = heightField;
heightFieldShapeDesc.shapeFlags = NX_SF_FEATURE_INDICES | NX_SF_VISUALIZATION;
heightFieldShapeDesc.group = 1;
heightFieldShapeDesc.heightScale = 18.8f;//1 в Physx = 255 в огре
heightFieldShapeDesc.rowScale = mTerrainOptions.scale.x;
heightFieldShapeDesc.columnScale = mTerrainOptions.scale.z;
heightFieldShapeDesc.meshFlags = NX_MESH_SMOOTH_SPHERE_COLLISIONS;
heightFieldShapeDesc.materialIndexHighBits = 0;
heightFieldShapeDesc.holeMaterial = 2;
ActorDesc.shapes.pushBack(&heightFieldShapeDesc);

我应该更改什么才能加载 16 位或更高版本的图像?

P.S.:抱歉英语不好

最佳答案

你的 pOrigSrc 是一个 uchar,它是 8 位的,所以当你这样做时你没有得到正确的偏移量:

pSrc = pOrigSrc + column*mPageSize +row;

您可以通过在循环之前首先捕获图像的步幅来解决此问题,如下所示:

int imageStride = mImage.getBPP() / 8;

然后将计算出的偏移量乘以步幅,如下所示:

pSrc = pOrigSrc + (column*mPageSize +row)*imageStride;

这应该允许您同时使用 8 位和 16 位高度贴图。 PhysX 仅支持 16 位高度贴图,因此您不能比这更高。

关于c++ - 如何在 Ogre3d 和 PhysX 中使用 16 位高度图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1047407/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com