NxOgreSample_Terrain,the height NxOgre tests is higher?

harr999y

06-07-2010 12:05:23

Hello,i just have tried the NxOgreSample_Terrain,but I have a litter question,please have a look at the pic below:

As you see,the collision is a litter higher.
Need help~Thank you ~ :)

[Edit]
And in some area of the terrain,it can't have a collision with the boxes.So strange,I'm sorry I really don't have the ability
to read the source code now :mrgreen:

Tibo6

06-07-2010 18:34:43

Oh, sounds like we have the same problem (mine is here).
What is your code ?

harr999y

07-07-2010 03:48:05

Oh, sounds like we have the same problem (mine is here).
What is your code ?

Yeah,I have saw your thread.I don't acttualy understand your desc as my poor English,so I make a new topic. :)
And now do you solve the problem? My code is just the same as NxOgreTutorials 117:

#include "NxOgreSample_Terrain.h"

void NxOgreSample_TerrainApp::setupPhysX()
{
using namespace NxOgre;
mWorld = World::createWorld();
NxOgre::ResourceSystem::getSingleton()->openProtocol(new Critter::OgreResourceProtocol());

SceneDescription sd;
sd.mGravity = Constants::MEAN_EARTH_GRAVITY;
sd.mUseHardware = true;
Scene * scene = mWorld->createScene(sd);
scene->getMaterial(0)->setAll(0.1f,0.9f,0.5f);
mRenderSystem = new Critter::RenderSystem(scene,mSceneMgr);
//mRenderSystem->setVisualisationMode(Enums::VisualDebugger_ShowAll);
//mRenderSystem->setVisualisationMode(Enums::VisualDebugger_);
}

void NxOgreSample_TerrainApp::destroyScene()
{
OGRE_DELETE mTerrainGroup;
OGRE_DELETE mTerrainGlobals;
NxOgre::World::destroyWorld();
}

void NxOgreSample_TerrainApp::createScene()
{
using namespace Ogre;
ColourValue background = ColourValue(135.0f/255.f, 206.f/255.f, 235.f/255.f);
//mCameraMan->getCamera()->getViewport()->setBackgroundColour(background);

// add a bright light above the scene
mLight = mSceneMgr->createLight();
mLight->setType(Light::LT_POINT);
mLight->setPosition(-10, 40, 20);
mLight->setSpecularColour(ColourValue::White);

mCameraMan->getCamera()->setPosition(10,10,10);
mCameraMan->getCamera()->lookAt(0,0,0);
mCameraMan->getCamera()->setNearClipDistance(0.02f);
mCameraMan->getCamera()->setFarClipDistance(10000.0f);
mCameraMan->setTopSpeed(1200);

mSceneMgr->setSkyBox(true, "Examples/CloudyNoonSkyBox");
mSceneMgr->setAmbientLight(ColourValue::White);

setupPhysX();

mTerrainGlobals = OGRE_NEW TerrainGlobalOptions();
mTerrainGroup = OGRE_NEW TerrainGroup(mSceneMgr, Terrain::ALIGN_X_Z, 513, 10000);
mTerrainGroup->setOrigin(Ogre::Vector3(0,30,0));

// Configure global
mTerrainGlobals->setMaxPixelError(8);
// testing composite map
mTerrainGlobals->setCompositeMapDistance(3000);
//mTerrainGlobals->setUseRayBoxDistanceCalculation(true);
//mTerrainGlobals->getDefaultMaterialGenerator()->setDebugLevel(1);
//mTerrainGlobals->setLightMapSize(256);

//matProfile->setLightmapEnabled(false);
// Important to set these so that the terrain knows what to use for derived (non-realtime) data
mTerrainGlobals->setLightMapDirection(mLight->getDerivedDirection());
mTerrainGlobals->setCompositeMapAmbient(mSceneMgr->getAmbientLight());
//mTerrainGlobals->setCompositeMapAmbient(ColourValue::Red);
mTerrainGlobals->setCompositeMapDiffuse(ColourValue::White);

// Configure default import settings for if we use imported image
Terrain::ImportData& defaultimp = mTerrainGroup->getDefaultImportSettings();
defaultimp.terrainSize = 513;
defaultimp.worldSize = 1000;
defaultimp.inputScale = 100;
defaultimp.minBatchSize = 33;
defaultimp.maxBatchSize = 65;
// textures
defaultimp.layerList.resize(3);
defaultimp.layerList[0].worldSize = 100;
defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_diffusespecular.dds");
defaultimp.layerList[0].textureNames.push_back("dirt_grayrocky_normalheight.dds");
defaultimp.layerList[1].worldSize = 30;
defaultimp.layerList[1].textureNames.push_back("grass_green-01_diffusespecular.dds");
defaultimp.layerList[1].textureNames.push_back("grass_green-01_normalheight.dds");
defaultimp.layerList[2].worldSize = 200;
defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_diffusespecular.dds");
defaultimp.layerList[2].textureNames.push_back("growth_weirdfungus-03_normalheight.dds");

Image img;
img.load("terrain.png", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
mTerrainGroup->defineTerrain(0, 0,&img);

mTerrainGroup->loadAllTerrains(true);
TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
while(ti.hasMoreElements())
{
Terrain* terrain = ti.getNext()->instance;
TerrainLayerBlendMap* blendMap0 = terrain->getLayerBlendMap(1);
TerrainLayerBlendMap* blendMap1 = terrain->getLayerBlendMap(2);
Ogre::Real minHeight0 = 70;
Ogre::Real fadeDist0 = 40;
Ogre::Real minHeight1 = 70;
Ogre::Real fadeDist1 = 15;
float * pBlend0 = blendMap0->getBlendPointer();
float* pBlend1 = blendMap1->getBlendPointer();
for (Ogre::uint16 y = 0; y < terrain->getLayerBlendMapSize(); ++y)
{
for (Ogre::uint16 x = 0; x < terrain->getLayerBlendMapSize(); ++x)
{
Ogre::Real tx, ty;

blendMap0->convertImageToTerrainSpace(x, y, &tx, &ty);
Ogre::Real height = terrain->getHeightAtTerrainPosition(tx, ty);
Ogre::Real val = (height - minHeight0) / fadeDist0;
val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);
*pBlend0++ = val;

val = (height - minHeight1) / fadeDist1;
val = Ogre::Math::Clamp(val, (Ogre::Real)0, (Ogre::Real)1);
*pBlend1++ = val;
}
}
blendMap0->dirty();
blendMap1->dirty();
//blendMap0->loadImage("blendmap1.png", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
blendMap0->update();
blendMap1->update();

// set up a colour map

/*if (!terrain->getGlobalColourMapEnabled())
{
terrain->setGlobalColourMapEnabled(true);
Image colourMap;
colourMap.load("RustedMetal.jpg", ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
terrain->getGlobalColourMap()->loadImage(colourMap);
}*/

}
mTerrainGroup->freeTemporaryResources();

ti = mTerrainGroup->getTerrainIterator();
while (ti.hasMoreElements())
{
Terrain * t = ti.getNext()->instance;
mRenderSystem->createTerrain(t);
}

//mRaySceneQuery = mSceneMgr->createRayQuery(Ogre::Ray());
}

void NxOgreSample_TerrainApp::frameRenderingQueued(const Ogre::FrameEvent& evt)
{
using namespace NxOgre;
mWorld->advance(evt.timeSinceLastFrame);
if (GetAsyncKeyState(VK_SPACE) && 0xff)
{
Critter::BodyDescription bodyDescription;
bodyDescription.mMass = 5340;
bodyDescription.mLinearVelocity = Vec3(0,-330,0);
NxOgre::BoxDescription box;
box.mSize.set(100,100,100);

Critter::Body* body = mRenderSystem->createBody(box, Vec3::random(-228,228,500,1228,-228,228), "cube.1m.mesh", bodyDescription);
body->getSceneNode()->setScale(100,100,100);

}

//up the terrain
/*Ogre::Vector3 camPos = mCameraMan->getCamera()->getDerivedPosition();
//Ogre::Terrain::rayIntersects()
Ogre::TerrainGroup::TerrainIterator ti = mTerrainGroup->getTerrainIterator();
Ogre::Real camY;
while (ti.hasMoreElements())
{
Ogre::Terrain * t = ti.getNext()->instance;
camY = mTerrainGroup->getHeightAtWorldPosition(camPos,&t);
}

mCameraMan->getCamera()->setPosition(camPos.x,camY,camPos.z);*/
}

Maybe we can change the mTerrainGroup->setOrigin(Ogre::Vector3(0,30,0)); to ajust it,but I don't think it's a good way.

harr999y

07-07-2010 03:57:30

Ok,I found that if I scale the terrainsize from 10000 to 513 it works great:

The position is Accurately .(It's static) :)

harr999y

07-07-2010 05:23:57

:) After my test,I have the conclusion but I don't know why:If the terrainSize == worldSize,then it's okay,works well.
Any suggestions?

Tibo6

07-07-2010 12:44:50

No I haven't a solution yet :(
Since I use Ogitor to create my terrain, I don't modify terrainSize and worldSize directly.

betajaen

07-07-2010 12:54:07

What does the visual debugger or the remote debugger look like?

harr999y

07-07-2010 13:36:10

What does the visual debugger or the remote debugger look like?
If I open the visual debugger FPS drops to 1,so I just test it as experiences.And after some tests,I found that the problem some areas can't collide causes by NxOgre::SceneGeometry* RenderSystem::createTerrain(Ogre::Terrain* terrain);
In the end of it NxOgre::Vec3 pose(terrain->getPosition());
pose.x -= float(size) / 2.0f;
pose.y += (maxHeight + minHeight) / 2.0f;
pose.z -= float(size) / 2.0f;

It's the question code.When our worldSize is bigger than terrainSize,it leads to the HeightFieldGeometry is smaller than how large it should be.So make it NxOgre::Vec3 pose(terrain->getPosition());
pose.x -= float(hf_size) / 2.0f;
pose.y += (maxHeight + minHeight) / 2.0f;
pose.z -= float(hf_size) / 2.0f;

Then it is Ok.
But another quetion as the first pic shows is still wrong.I change the defaultimp.inputScale = 600(or other big num);
//the smaller the num is,the smaller relief,and the better it works.
and change the code from CritterRenderSystem.cpp for(int x = 0; x < size; ++x)
{
sample.mTessellationFlag = NxOgre::Enums::HeightFieldTesselation_NW_SE;
for(int z = size-1; z >= 0; --z)
{
float height = ter_data[(size * z) + x];
sample.mHeight = (short) ( ( (height - minHeight) / heightDiff) * normDiff + normMin) - 20.0f; :lol:
data.mSamples.push_back(sample);
sample.mTessellationFlag = sample.mTessellationFlag;
}
}
After this,it looks like a litter better,but still have some Pass-Through. :(
So,then i think the reason is when we scale the terrain to worldSize,the height infomation goes to the HeightFieldSample and HeightFieldData is a litter unadapted with what we need.Do you have any solutions?Thanks,betaJean! :)

betajaen

07-07-2010 13:50:38

Open the RemoteDebugger and connect it to your app, set the camera in the remote debugger to the same position/direction as the one in Ogre and compare the differences.

harr999y

07-07-2010 13:55:11

Open the RemoteDebugger and connect it to your app, set the camera in the remote debugger to the same position/direction as the one in Ogre and compare the differences.
Ok,I'll try it.Wait a while :)

harr999y

07-07-2010 14:21:56

I'm very sorry that when I use the PhysX2.83,the debegger crashes.And when I use 2.81,it comes a error:Invalid event encountered.This is probably caused by a bug in the debug stream writing.The stream will be locked,but can still be saved. :shock:

shanefarris

08-07-2010 06:18:10

I'm having the same problem, the terrain is off by a little bit, and the terrain was created in Ogitor as well.

harr999y

08-07-2010 12:13:12

I'm having the same problem, the terrain is off by a little bit, and the terrain was created in Ogitor as well.
Yeah,let's wait for betajean's back.It's a so strange problem

betajaen

08-07-2010 12:44:36

Okay, Height-field cooking and creation works.

NxOgre::ManualHeightField mhf;
unsigned int rows = 16;
unsigned int cols = 16;

mhf.begin(rows,cols);
for (unsigned int i=0;i < rows * cols;i++)
{
mhf.sample(i * 128);
}
NxOgre::HeightField* hf = mhf.end(true, "file://testy.xhf");

HeightFieldGeometryDescription hfd = HeightFieldGeometryDescription(hf, Vec3(16,16,16));
hfd.mFlags += ShapeFlags::Visualisation;
mScene->createSceneGeometry(hfd);


[attachment=0]terrain1.jpg[/attachment]


However, I found that cooking the heightfield to memory (memory://) causes a crash. So try cooking your heightfields to files. You should only need to cook the heightfield once anyway, not every time you create it in Ogre.

I'll try and track down the memory problem another day, but if you still get a crash after cooking to a file, then it's certainly the Ogre terrain to XHF code.

harr999y

08-07-2010 12:59:28

Betajaen,thanks for reply again.I'll try it. :)

harr999y

08-07-2010 13:53:33

Okay, Height-field cooking and creation works.

Yeah,I use it instead of the
NxOgre::HeightField* hf = data.cookQuickly();
It works very well.When scale the worldsize to 100,the FPS up to 30+.And see the pic
[attachment=0]Ogre_Framework 2010-07-08 20-37-37-52.jpg[/attachment]
You can see that the heght information has some questions.Just higher or lower.
Now the terrainSize is 65,worldSize is 100.

However, I found that cooking the heightfield to memory (memory://) causes a crash. So try cooking your heightfields to files.
I'll try and track down the memory problem another day, but if you still get a crash after cooking to a file, then it's certainly the Ogre terrain to XHF code
Do you mean cook the heoghtfield to file can make the RemoteDebugger runing well?I just tried both,but it still can't work.And luckily I get the pic as the problem shows,so I don't need to wait for solving the problem of RemoteDebugger.
So,how do you think about the problem with the height info incorrectly? :)
Thanks~
Harry

Tibo6

08-07-2010 14:58:45

So, it works with you ?
What have you changed ?

betajaen

08-07-2010 15:13:31

I just looked this up,

"cookQuickly" by passes the resource system and doesn't use any files, so therefore is quicker. If you use the normal way, first it saves it as a heightfield to disk/memory then re-loads it in. So "cookQuickly" it won't be affected by the memory crash and my version of the Ogre Terrain to Heightfield code uses this.

It looks like that the scaling is down to the scale given by the Terrain to Heightfield code, both mine and the wiki version are the same. So if you can figure out that then that should be the fix.

harr999y

09-07-2010 03:46:38

So, it works with you ?
What have you changed ?

I'm sorry that I don't know your point clearly :) Do you mean the collision test works well or something?

harr999y

09-07-2010 03:53:05


It looks like that the scaling is down to the scale given by the Terrain to Heightfield code, both mine and the wiki version are the same. So if you can figure out that then that should be the fix.

Okay,I'm trying my best to fix this problem.But I'm actually a really Newbie,so maybe it'll be a very long time. :lol:

betajaen

09-07-2010 10:31:31

I'm pretty sure it's the scale anyway, if you look at the contour on the image above. Look at the middle right and you can see the red heightfield following the Ogre Terrain, even though they are at different scales or positions. If the terrain data was changed or corrupted in cooking it would be more random and sharper.

harr999y

09-07-2010 13:50:46

I'm pretty sure it's the scale anyway, if you look at the contour on the image above. Look at the middle right and you can see the red heightfield following the Ogre Terrain, even though they are at different scales or positions. If the terrain data was changed or corrupted in cooking it would be more random and sharper.
Yeah,the scale has some questions.But,it seems that I fixed it.See:
[attachment=2]Ogre_Framework 2010-07-09 20-33-50-34.jpg[/attachment]
[attachment=1]Ogre_Framework 2010-07-09 20-34-01-42.jpg[/attachment]
[attachment=0]Ogre_Framework 2010-07-09 20-35-35-52.jpg[/attachment]
(The red line and the white line which place the Ogre terrain nearly coincide)
It's terrainSize 65,worldSize 1000,and inputScale with heightMap 300.The heightInfo is correct now. :)
I altered the code in CritterRenderSystem.cpp NxOgre::SceneGeometry* RenderSystem::createTerrain(Ogre::Terrain* terrain) to:
Ogre::Real wSize = terrain->getWorldSize(); //Here~
const float hf_size = float(terrain->getWorldSize()) + (float(terrain->getWorldSize()) / float(size));
const float hf_height = (maxHeight - minHeight) / 2.0f;
NxOgre::Vec3 pose(terrain->getPosition());
pose.x -= (float(wSize) / 2.0f - 0.005f); //Here~
pose.y += (maxHeight + minHeight) / 2.0f;
pose.z -= (float(wSize) / 2.0f - 0.01f); //Here~

NxOgre::HeightFieldGeometryDescription hf_desc;
hf_desc.mHeightField = hf;
hf_desc.mLocalPose.set(pose);
hf_desc.mDimensions.set(hf_size, hf_height, hf_size); //Here~

And yeah,just as look.But now I'm confused about that the collision test in PhysX seems to a litter strange.I'll put the pic next reply as Cannot add another attachment, 3 is the maximum. :mrgreen:

harr999y

09-07-2010 13:56:20

[attachment=0]Ogre_Framework 2010-07-09 20-35-21-43.jpg[/attachment]
As you see carfully (:)sorry for the pic size limit) ,the box is inside and down the Ogre terrain plane and even the PhysX colission plane.I really can't imagine why this occur,.:( I'll continue to fix it~ Thanks for your attention,betaJean :)

harr999y

09-07-2010 14:46:21

I'm pretty sure it's the scale anyway, if you look at the contour on the image above. Look at the middle right and you can see the red heightfield following the Ogre Terrain, even though they are at different scales or positions. If the terrain data was changed or corrupted in cooking it would be more random and sharper.
Er,finally I get your idea.Sorry for my bad English. :mrgreen: Because when I make the terrainSize 65,worldSize 10000,then it comes a bigger diffrence which I konw I don't solve it.
[attachment=0]Ogre_Framework 2010-07-09 21-35-23-70.jpg[/attachment]
I have tried my best,next maybe I'd better wait for you or others' solutions as my low knowledge about it.Because my time limit,I have to go to learn the Caracter Controll :) .
If you have some time,please kill it.Thank you :wink:
Harry

Fr0stY

14-07-2010 02:32:03

dunno if this helps... I was having the same problem and, in the terrainGroup properties in ogitor, I changed the World Size and Map Size to 128 and 128x128; it fixed the offset problem. I guess this means that the problem must be related to errors in math calculations? (like different precisions or something).
I didn't try this without harr999y code fix.

I'm also new to ogre btw : P

harr999y

14-07-2010 04:03:52

dunno if this helps... I was having the same problem and, in the terrainGroup properties in ogitor, I changed the World Size and Map Size to 128 and 128x128; it fixed the offset problem. I guess this means that the problem must be related to errors in math calculations? (like different precisions or something).
I didn't try this without harr999y code fix.

I'm also new to ogre btw : P

Thanks for your sharing. :)
I also find that when the terrainSize(or mapSize) is equal to the wroldSize,it works well.But the problem is if we need a big world,then it's a litter offset.And yeah,maybe it's caused by math calculations.I find that from the pic,it's not only the heightInfo offset,but also the vertex position offset.So,come on,let's solve it! :)