How are heightmap values used?

kungfoomasta

19-02-2008 03:41:29

I'm trying to use the heightmap data directly to create my PhysX heightfield object, and as you will see, the shape does not match the terrain:



From the looks of it, the Shape is rotated and mirrored...

Code:


ET::TerrainInfo* i = mTerrainComponent->mTerrainInfo;
std::vector<float> heightData = i->getHeightmapData();
for(std::vector<float>::iterator it = heightData.begin(); it != heightData.end(); ++it)
{
NxHeightFieldSample* currentSample = (NxHeightFieldSample*)currentByte;

currentSample->height = static_cast<NxI16>(((*it) * 65535) - 32768);
currentSample->materialIndex0 = 0;
currentSample->materialIndex1 = 0;

currentSample->tessFlag = 0;

currentByte += mNxHeightFieldDesc.sampleStride;
}


This question is mostly aimed at CABAListic: How should I be iterating through the heightmap values? It doesn't seem like I can take this approach, right?

Is it possible to request the heightmap data be iterated like this to build the terrain in the future? I realize it wont' work on a Terrain level, but if I could use this approach per Tile that would be awesome. I remember you saying you were going to make Tiles more accessible. If they gave access to their heightmap data and I could simply iterate through it to create a tile shape, that would be ideal.

SongOfTheWeave

19-02-2008 06:29:25

You're iterating backwards. Swap your x and your z.

[Edit]
Oh I see what you're trying to do. You're going to have to do math to read through the heightmap in an ass backwards way because physx expects the heightmap in a particular manner (see physx docs for the explanation of this, I forget exactly where it was.)

I suggest using the nested for loop method instead. It works.

SongOfTheWeave

19-02-2008 06:34:52

I can also fix your CEGUI bug.

When it up samples the graphics from the imageset it blends in the next pixel OUTSIDE the range specified in the imageset. Expand all your window border graphics by 1 pixel and keep their areas the same in the imageset file.

ex:

MyWindow xpos=1 ypos=1 height=6 width=6

then have your image actually span from (0, 0) to (8, 8) that way when it interpolates from the pixel just outside the image, it grabs an appropriate pixel rather than black, or transparent.

kungfoomasta

19-02-2008 06:58:42

Odd, I tried the double for loop earlier and it didn't work. Now I try it again and it looks correct...


for (NxU32 row = 0; row < mNxHeightFieldDesc.nbRows; row++)
{
for (NxU32 column = 0; column < mNxHeightFieldDesc.nbColumns; column++)
{
NxHeightFieldSample* currentSample = (NxHeightFieldSample*)currentByte;

currentSample->height = static_cast<NxI16>(((i->at(row,column)) * 65535) - 32768);
currentSample->materialIndex0 = 0;
currentSample->materialIndex1 = 0;

currentSample->tessFlag = 0;

currentByte += mNxHeightFieldDesc.sampleStride;
}
}


Well it appears to be working... :lol:

I'm using QuickGUI and not CEGUI. I haven't really put much effort into the skin or anything, but I think you're right about the images.

SongOfTheWeave

19-02-2008 07:32:15

Well it appears to be working... :lol:

Good! Now go work on my lighting problem *Cracks whip*

I'm using QuickGUI and not CEGUI. I haven't really put much effort into the skin or anything, but I think you're right about the images.

Ah, CEGUI exhibits the same behaviour. I ran into it a couple weeks back.