Terrain Creator Code Problem

Crhonos

12-08-2011 23:49:43

I found this code in the Ogre Tutorials Page.It was made for bloodymess.

void loadTerrainGeometry(const Ogre::String& name, float* data, Ogre::uint16 size, Ogre::Real worldSize, Ogre::Real minHeight, Ogre::Real maxHeight, const Ogre::Vector3& position)
{
// Create the manual heightfield
NxOgre::ManualHeightField *mhf = OGRE_NEW_T(NxOgre::ManualHeightField, Ogre::MEMCATEGORY_GENERAL)();
mhf->begin(size, size);
Ogre::Real normMin = -32768.0f;
Ogre::Real normMax = 32767.0f;
// Sample the data to the manual heightfield
for(int x = 0; x < size; ++x)
{
NxOgre::Enums::HeightFieldTesselation tess = NxOgre::Enums::HeightFieldTesselation_NW_SE;

for(int z = size-1; z >= 0; --z)
{
Ogre::Real height = data[(size * z) + x];
short sample = (short)(((height - minHeight) / (maxHeight - minHeight)) * (normMax - normMin) + normMin);
mhf->sample(sample, 0, 0, tess);
if(tess == NxOgre::Enums::HeightFieldTesselation_NE_SW)
tess = NxOgre::Enums::HeightFieldTesselation_NW_SE;
else
tess = NxOgre::Enums::HeightFieldTesselation_NE_SW;
}
}
// Create the actual heightfield
NxOgre::HeightField *hf = mhf->end(name.c_str());
Ogre::Real hf_size = worldSize + (worldSize / size);
Ogre::Real hf_height = (maxHeight - minHeight) / 2.0f;
Ogre::Real hf_pose_x = position.x - (worldSize / 2.0f);
Ogre::Real hf_pose_y = position.y + ((maxHeight + minHeight) / 2.0f);
Ogre::Real hf_pose_z = position.z - (worldSize / 2.0f);
#if NxOgreVersionMajor <= 1 && NxOgreVersionMinor <= 5
NxOgre::HeightFieldGeometry* hfg = new NxOgre::HeightFieldGeometry(hf, NxOgre::Vec3(hf_size, hf_height, hf_size));
hfg->setLocalPose(NxOgre::Matrix44(NxOgre::Vec3(hf_pose_x, hf_pose_y, hf_pose_z)));
mScene->createSceneGeometry(hfg);
#else
NxOgre::HeightFieldGeometryDescription desc(hf, NxOgre::Vec3(hf_size, hf_height, hf_size));
mScene->createSceneGeometry(desc, NxOgre::Matrix44(NxOgre::Vec3(hf_pose_x, hf_pose_y, hf_pose_z)));
#endif
// Free memory
OGRE_DELETE_T(mhf, ManualHeightField, Ogre::MEMCATEGORY_GENERAL);
}

It can be found here: http://www.ogre3d.org/tikiwiki/BloodyMe ... =Libraries

I am using the last version of critter and Nxogre, physx sdk 2.8.4 and i am fairly new to Nxogre.But as Buggyswires was the only version that worked here i started to learn how to use it.
At the begging it was really dificult(and yet it is) but it got easyer after some effort.

Anyway i knewd that the Bloodymess code was not going to work, that i would have to adapt the code.And i was going to do so, but i got stuck in the very begging because of an error that the debuuger acuses in this line:

NxOgre::ManualHeightField *mhf = OGRE_NEW_T(NxOgre::ManualHeightField, Ogre::MEMCATEGORY_GENERAL)();

The error is "wrong number of arguments, this code does not suport 2 arguments" something like that, but written in a diferent way(close but diferent).
The problem is that, if i use less arguments i get an error complaining about having less arguments u.u

Anyway, if anyone could fix that code( this part especially or the entire code) i will be gratefull ^^

off; Also there is any way to make the buggyswires tutorial samples in a vc9 project ?

Thanks in advance.

deshan

13-08-2011 08:00:12

as i can remember betajaen mentioned it multiple times to use stack memeory here

NxOgre::ManualHeightField mhf;
mhf.begin(size, size);

Crhonos

13-08-2011 13:26:12

Thanks ^^ It's working now XD

mahdie9

06-09-2011 17:45:29

Crhonos,

Can you insert the initial code of Ogre::Terrain object?
I know the function is needed to be called like this:

loadTerrainGeometry(terrain->getMaterialName(), terrain->getHeightData(), terrain->getSize(), terrain->getWorldSize(), terrain->getMinHeight(), terrain->getMaxHeight(), terrain->getPosition());

But I know nothing on how to initilize *terrain pointer.

looking forward,