[BloodyMess] Using NxOgre with Ogre Terrain

Rydinare

05-05-2009 00:55:28

Hi all. I've been searching through the forums trying to figure this out properly, but unfortunately I'm running into difficulties. What I'm gathering is that NxOgre "used to" have something called a TerrainShape and a Terrain actor and these no longer exist? I must've come across at least 10 examples that used these methods, but they are not available in my copy of NxOgre "Bloody Mess", which is a shame because they would make things much simpler. I get it that NxOgre is meant to not be specifically bound to Ogre, but it doesn't really make sense that utility facilities to make this simpler are no longer provided, so perhaps I'm misunderstanding something. I get that you can use Photoshop and then flour to convert to a NxOgre compatible heightmap, but this is not what I'm looking for, since it requires duplication of assets.

Can anyone please advise? I can't find good documentation on this, as so far, the wiki and other reference sites on the matter are very incomplete.

Thanks in advance.

Rydinare

05-05-2009 02:18:47

Also, I wanted to post, here's the code I've come up with so far:


NxOgre::HeightField* heightFieldFromImage(NxOgre::ManualHeightField& p_heightField, const std::string& p_heightMap)
{
Ogre::Image image;
image.load(p_heightMap, "General");
Ogre::uchar* pData = image.getData();

size_t imageHeight = image.getHeight();
size_t imageWidth = image.getWidth();
size_t imageBpp = image.getBPP();

p_heightField.begin(imageHeight, imageWidth);

if (imageBpp == 8)
{
for (size_t i = 0; i < imageHeight; ++i)
{
for (size_t j = 0; j < imageWidth; ++j)
{
Ogre::ColourValue colorValue = image.getColourAt(i, j, 0);
int c = colorValue.r;
int t = (c * 256) - (32768);
short height = short(t);
p_heightField.sample(height);
} // end for
} // end for
} // end if

return p_heightField.end("terrain");
}

...

NxOgre::ManualHeightField heightField;
NxOgre::HeightField* pTerrain = heightFieldFromImage(heightField, "terrain.png");



However, it doesn't seem to have any effect. Is there something I have to do to "attach" it in my scene? I saw "Bleeding" examples use Actors, but I couldn't figure out how to do it with a HeightField. Thanks.