c++ - How to use 16bit heightmaps with Ogre3d and PhysX -


I am using Augrey 3D and Physics.

When I load an area from an 8bit height map, this view looks normal on the debugger.

Look at the first image:

But when I save the height map as a 16 bit image, I get what you see on the second image.

>

Here is the code, it works normally with 8bit PNG:

  mSceneMgr-> Setgreatmetry ("terrain.cfg"); MTSM = static_cast & lt; TerrainSceneManager * & gt; (SceneMgr); TerrainOptions mTerrainOptions = mTSM- & gt; GetOptions (); // Load heihgtmap image mimage; MImage.load ("isl_h_ph.png", Resource Group Manager: GetSellingington (.) GetWorldResourceGroupName ()); // Load image / image buffer type pOrigSrc const uchar * pOrigSrc = mImage.getData (); Const uchar * pSrc; // Image size mPageSize size_t mPageSize = mTerrainOptions.pageSize; NxActorDesc ActorDesc; // Set height height of field FieldDesc = New NxHeightFieldDesc; HeightFieldDesc-> NbColumns = mPageSize; HeightFieldDesc-> NbRows = mPageSize; HeightFieldDesc-> Vertical espress = -1000; HeightFieldDesc-> Convex adrestrowhold = 0; HeightFieldDesc-> Samples = New NxU32 [mPageSize * mPageSize]; // Constructor for each sample? HeightFieldDesc-> Sample Swavid = Size (NxU32); // Some sample steps = number of samples pSrc = pOrigSrc; Char * currentByte = (four *) heightFieldDesc- & gt; Samples; // Existing sample MB? LogManager :: getSingletonPtr () - & gt; LogMessage ("+++ Heightmap ---"); ({NxU32 column = 0; column & lt; mPageSize; column ++} // circle around the sample {pSrc = pOrigSrc + column * mPageSize + (for the NxU32 line = 0; line & lt; mPageSize; line ++) Row; // NxReal s = NxReal (line) / NxReal (mPageSize); // NxReal T = NxReal (column) / NxReal (mPageSize); NXI 16 height = (NXI 32) (* PSRC ++); NxU32 matrix offset = (line% gMatrixSize) * gMatrixSize + (column% gMatrixSize); // LogManager :: getSingletonPtr () - & gt; LogMessage (Indoor :: StringConverter :: toString (height)); NxHeightFieldSample * Current sample = (NxHeightFieldSample *) currentByte; CurrentSample-> Height = height; CurrentSample-> Contentindx 0 = gmatrix [matrix offset] [1]; CurrentSample-> Physical index 1 = gmatrix [matrix offset] [2]; CurrentSample-> TessFlag = gMatrix [matrix offset] [0]; CurrentByte + = heightFieldDesc- & gt; Sampleroid; }} HeightField = mScene-> GetPhysicsSDK (). Vs. hitfield (* heightFieldDesc); NxHeightFieldShapeDescHighfieldSpeedDesk; Heightfile shipmentdice Highfield = heightfield; Height FieldShap Required CRAPFLAG = NX_SF_FEATURE_INDICES | NX_SF_VISUALIZATION; HeightFieldShapeDesc.group = 1; HeightFieldShapeDesc.heightScale = 18.8f; // 1D Physics = 255 degree heightFileShare Dies.Roskel = MTRON option. Scale. X; AltitudeShapeddesign Columnsle = MeterOption. Scale. Z; Height fieldShapDice Mistflags = NX_MESHMMHOHHSSPHREACA HeightFieldShapeDesc.materialIndexHighBits = 0; HeightFieldShapeDesc.holeMaterial = 2; ActorDesc.shapes.pushBack (& ​​heightFieldShapeDesc);  

Loading 16bit or more image should I change to work?

PS: Sorry for bad english

Your pOrigSrc is an extract, Which is 8 bits, so when you do this, you are not getting the correct offset:

  PSrc = pOrigSrc + column * mPageSize + row;  

You can first correct it by grabbing your image before your loops, something like this:

  int imageStride = mimage.getBPP () / 8;  

And then increase your calculation count by multiplying, something like this:

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

This should allow you to use both 8-bit and 16-bit height maps. PhysX only supports a 16-bit height map, so you can not go any further than that.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -