[Bleeding] Terrain help

CHICO

03-09-2008 12:11:15

Hey, I'm trying to get terrain working from a manual heightfield but I'm having issues, probably due to a lack of understanding on my part. There are 2 issues that I'm having. The first is that I can't figure out how to get the NxOgre visualization working even though the terrain is displayed in the debugger. The second is that the 2 test cubes fall right through the terrain in the debugger as if the terrain wasn't even there.

Here is a screenshot of the debugger and the associated NxOgre window. You can see that even though there are cube-terrain contacts being generated, the cubes are passing through the terrain.


Here is some of the code I am using (its spread across a few functions):


//Create World and main scene
NxOgre::PhysXParams pparams;
pparams.mTimeController = NxOgre::PhysXParams::TC_PTR;
pparams.mCustomTimeControllerPtr = time;
world = new NxOgre::World(pparams);

//attach physX driver to time controller
time->physXDriver = world->getPhysXDriver();

//Attach to debugger
world->getPhysXDriver()->createDebuggerConnection();

//Create physics scene
NxOgre::SceneParams sparams;
sparams.mRenderer = NxOgre::SceneParams::RN_OGRE;
sparams.mController = NxOgre::SceneParams::CN_VARIABLE;
sparams.mSceneFlags.mSimulateSeperateThread = false;
sparams.mGravity = NxVec3(0, 0, 0);
sparams.mFloor = false;
sparams.mMaxTimestep = 1.0f;
scene = world->createScene("NABEMphysics",sparams);

//Add land and sea materials
land = scene->createMaterial("land");
land->setAll(0.1,0.1,0.1);
usea = scene->createMaterial("usea");
usea->setAll(0.1,0.1,0.1);


//Start the heighfield creation by initializing the manual heightfield
NxOgre::Resources::ManualHeightfield* mhf = new NxOgre::Resources::ManualHeightfield();
mhf->setTesselation(NxOgre::Resources::ManualHeightfield::TT_TopLeft_to_BottomRight);
mhf->begin(cols, rows);

//Add each data point to the heightfield (row major order)
for(GridMapIndex i = 0; i != rows; ++i)
for(GridMapIndex j = 0; j != cols; ++j)
{
NxMaterialIndex matInd = land;
short datum = (*data)[i][j];

//Set the material for undersea if below sea level
if(datum < 0) matInd = usea;

//Add sample to heightfield
mhf->sample(datum,matInd);
}

//Set how far down the bottom of the heighfield extends
mhf->setThickness(maxHeight - minHeight);

NxOgre::Resources::Heightfield* hf = mhf->end(true);


void SimulationPhysics::addHeightField(NxOgre::Resources::Heightfield *hf, Point3D *botLeft, Point3D *topRight, int maxHeight)
{
//Calculate size of the terrain
double xWidth = topRight->x - botLeft->x;
double yWidth = topRight->y - botLeft->y;

//Set up the terrain parameters
NxOgre::TerrainParams tparams;
tparams.mCentering = NxOgre::TerrainParams::TC_CenterXZ;
tparams.mHoleMaterial = 65535;
tparams.mFlags.mVisualiseTerrain = true;

//Create the terrain
NxOgre::Terrain* terrain = new NxOgre::Terrain(hf, NxOgre::float3(xWidth,maxHeight,yWidth), "", tparams);
scene->createActor("terrain_actor", terrain, Ogre::Vector3(0,0,0), "static: yes");

//Add test object to the scene
NxOgre::ActorParams aparams;
aparams.mMass = 15;
scene->createBody("Cube1; cube.10m.mesh", new NxOgre::Cube(10), Ogre::Vector3(0, 100, 10), aparams);
scene->createBody("Cube2; cube.10m.mesh", new NxOgre::Cube(10), Ogre::Vector3(10,100, 0), aparams);
}


Any help would be appreciated.

betajaen

03-09-2008 12:30:33

I can't test your code in my Cake until I finish of IceCream, but there was two things that stood out.

1. Thickness of the terrain. For some reason my brain is telling me, it must be negative, however looking at the SDK documentation, it could be about the verticalExtent.

2. No gravity. Any contacts that may happen could be due to the cubes spawning inside the terrain (or partially).


You said not being able to see the Terrain in the DebugRenderer? I see you've found the secret terrain visualisation switch, but did you turn on the debug renderer?

mWorld->createScene(mSceneMgr);


Like I said, I would try out your code (or most of it), in Cake 4.0, but "IceCream" is being a bit of a pain and I need to finish that first.

CHICO

03-09-2008 12:51:38

I can't test your code in my Cake until I finish of IceCream, but there was two things that stood out.

1. Thickness of the terrain. For some reason my brain is telling me, it must be negative, however looking at the SDK documentation, it could be about the verticalExtent.


Cheers! Setting the thickness to the negative value worked and the test cubes are stopping at the terrain. Thanks Betajaen.


2. No gravity. Any contacts that may happen could be due to the cubes spawning inside the terrain (or partially).


I didn't even notice that gravity was turned off because the cubes were moving downward. I guess because the thickness was positive, the terrain was upside down and the cubes were pushed up, which in this case means pushed down.


You said not being able to see the Terrain in the DebugRenderer? I see you've found the secret terrain visualisation switch, but did you turn on the debug renderer?

mWorld->createScene(mSceneMgr);



Sorry to be so dense, but I'm very confused with what you said here. The problem is that I can see the terrain showing up in the Nvidia visual remote debugger, but not in the Ogre window. Do I have to do something besides what I already have in the code to visualize the terrain in the Ogre window?

betajaen

03-09-2008 13:06:58

Wow. Score one for Betajaen's Brain.

The Ogre Visual Render (the scene which you see in the Remote Debugger which is rendered onto the Ogre window) is enabled with the code I put above; but I turned off visualisation of terrain for performance reasons, you found the secret option which turns it's back on.

CHICO

03-09-2008 13:57:06

Wow. Score one for Betajaen's Brain.

The Ogre Visual Render (the scene which you see in the Remote Debugger which is rendered onto the Ogre window) is enabled with the code I put above; but I turned off visualisation of terrain for performance reasons, you found the secret option which turns it's back on.


I tried adding:
scene = world->createScene(sceneManager); and it didn't compile. I then tried adding scene = world->createScene("N2",sceneManager); and it wouldn't update the scene. So I tried replacing the line scene = world->createScene("NABEMphysics",sparams); with scene = world->createScene("NABEMphysics",sceneManager,sparams); and the terrain still isn't showing up. Here is the screenshot of the debugger vs the Ogre window:



Thanks!

betajaen

03-09-2008 13:59:03

Whoops. I wrote the wrong code snippet.

mWorld->createDebugRenderer(mSceneMgr);

Put that after the mWorld->createScene(...) code.

CHICO

03-09-2008 14:14:33

Whoops. I wrote the wrong code snippet.

mWorld->createDebugRenderer(mSceneMgr);

Put that after the mWorld->createScene(...) code.


I tried
scene = world->createScene("NABEMphysics",sparams);
world->createDebugRenderer(sceneManager);


and
scene = world->createScene("NABEMphysics",sceneManager,sparams);
world->createDebugRenderer(sceneManager);


But its still not showing the terrain.

betajaen

03-09-2008 14:16:28

Hmm. This is still in your terrain params?

tparams.mFlags.mVisualiseTerrain = true;

CHICO

03-09-2008 14:23:33

Hmm. This is still in your terrain params?

tparams.mFlags.mVisualiseTerrain = true;


Yes, sir.

betajaen

03-09-2008 14:37:27

Hmm, try this:

mWorld->getPhysXDriver()->setVisualisationCollisionShapesEnabled(true);

CHICO

03-09-2008 14:51:05

Hmm, try this:

mWorld->getPhysXDriver()->setVisualisationCollisionShapesEnabled(true);


Still nothing.

I'm starting to get this feeling that I'm doing the terrain incorrectly and that its not showing up because I'm not assigning textures/colors correctly to the terrain. What do you think?

betajaen

03-09-2008 15:06:35

No, it's physics. Newtonian physics don't describe how things look just how they behave and react with each other.

CHICO

03-09-2008 20:43:01

Hey, I've been tinkering with it some more since my last post and I have a few more questions. Here is the terrain creation code:

NxOgre::Terrain* terrain = new NxOgre::Terrain(hf, NxOgre::float3(xWidth,maxHeight,yWidth), "", tparams);
scene->createActor("Terrain", terrain, Ogre::Vector3(0,0,0), "static: yes");


1) Should I be calling some form of scene->createBody() instead of scene->createActor() ?

2) When I call NxOgre::Actor *A1 = scene->getActor("Terrain");

Should "A1->mVoidPointer->RenderPtr" be null?

Thanks

mcaden

04-09-2008 06:50:34

If you only create an actor you'll be able to collide with it, but not see it.

A body basically == an actor + an ogre SceneNode.

Either way should show up in the debug renderer, but just an actor won't be rendered.