how to use Heightmap terrain in NxOgre?

Leeman

11-06-2007 09:10:43

Who can tell me how to use terrain in nxogre? I follow the Betajaen's quick guide , but my body ( created with createBody ) not fall to the terrain , it float above the terrain! And my character can't move.
here is my code:

mWorld = new NxOgre::World( "FrameListener: Yes, log: text" );

mNxScene = mWorld->createScene("Main", mSceneMgr, "gravity:yes, floor:yes");

mSceneMgr -> setWorldGeometry( "terrain.cfg" );

mActor = mNxScene->createActor("terrain", new TerrainShape("terrain.png", 4096, 100, 513,513, "material:terrain_texture.jpg"), Vector3::ZERO, "static: yes");

mNxScene->createBody("B2_02_TianJian_HY1.mesh",new CubeShape(1,1,1), Vector3(707,1000,528), "Mass:100");

mCharacter = mNxScene->createCharacter("robot", Vector3(707,100,528), "type:box,dimensions:1 2 1");
mCharacter->attachMesh("robot.mesh");
//mCharacter->getNode()->scale(1,2,1);
mCharacter->getNode()->attachObject(mCamera);
mCamera->setPosition(Vector3(707,100,528));


and the terrain.cfg:

# The main world texture (if you wish the terrain manager to create a material for you)
WorldTexture=terrain_texture.jpg

# The detail texture (if you wish the terrain manager to create a material for you)
DetailTexture=terrain_detail.jpg

#number of times the detail texture will tile in a terrain tile
DetailTile=3

# Heightmap source
PageSource=Heightmap

# Heightmap-source specific settings
Heightmap.image=terrain.png

# If you use RAW, fill in the below too
# RAW-specific setting - size (horizontal/vertical)
#Heightmap.raw.size=513
# RAW-specific setting - bytes per pixel (1 = 8bit, 2=16bit)
#Heightmap.raw.bpp=2

# How large is a page of tiles (in vertices)? Must be (2^n)+1
PageSize=513

# How large is each tile? Must be (2^n)+1 and be smaller than PageSize
TileSize=65

# The maximum error allowed when determining which LOD to use
MaxPixelError=3

# The size of a terrain page, in world units
PageWorldX=1500
PageWorldZ=1500
# Maximum height of the terrain
MaxHeight=100

# Upper LOD limit
MaxMipMapLevel=5

#VertexNormals=yes
#VertexColors=yes
#UseTriStrips=yes

# Use vertex program to morph LODs, if available
VertexProgramMorph=yes

# The proportional distance range at which the LOD morph starts to take effect
# This is as a proportion of the distance between the current LODs effective range,
# and the effective range of the next lower LOD
LODMorphStart=0.2

# This following section is for if you want to provide your own terrain shading routine
# Note that since you define your textures within the material this makes the
# WorldTexture and DetailTexture settings redundant

# The name of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE HIGH-LEVEL VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamName=morphFactor

# The index of the vertex program parameter you wish to bind the morph LOD factor to
# this is 0 when there is no adjustment (highest) to 1 when the morph takes it completely
# to the same position as the next lower LOD
# USE THIS IF YOU USE ASSEMBLER VERTEX PROGRAMS WITH LOD MORPHING
#MorphLODFactorParamIndex=4

# The name of the material you will define to shade the terrain
#CustomMaterialName=TestTerrainMaterial




and here is the code I expect it move the character:

if (mKeyboard->isKeyDown(KC_A) || mKeyboard->isKeyDown(KC_LEFT)) {
mCharacter->addMovement(Character::DR_StepLeft);
}
else if (mKeyboard->isKeyDown(KC_D) || mKeyboard->isKeyDown(KC_RIGHT)) {
mCharacter->addMovement(Character::DR_StepRight);
}
else if (mKeyboard->isKeyDown(KC_W) || mKeyboard->isKeyDown(KC_UP)) {
mCharacter->addMovement(Character::DR_Forward);
}
else if (mKeyboard->isKeyDown(KC_S) || mKeyboard->isKeyDown(KC_DOWN)) {
mCharacter->addMovement(Character::DR_Backward);
}

betajaen

11-06-2007 09:37:23

I noticed your TerrainSize is 1500, adjust the TerrainShape to:

Actor = mNxScene->createActor("terrain", new TerrainShape("terrain.png", 1500, 100, 513,513, "material:terrain_texture.jpg"), Vector3::ZERO, "static: yes");

Leeman

11-06-2007 10:04:24

Thank you.
I change the size , the body seems not float now. But the charactor still can't move, and there is a black plane under the terrain.
here is the screenshot:

betajaen

11-06-2007 10:28:22

Is the character on the terrain, or on the black plane?

Leeman

11-06-2007 12:17:23

on the terrain

Leeman

11-06-2007 13:00:21

HI Betajaen, could you give me some sample code for moving character?
I add these code in frameStarted(...), but it doesn't work.

if (mKeyboard->isKeyDown(KC_A) || mKeyboard->isKeyDown(KC_LEFT)) {
mCharacter->addMovement(Character::DR_StepLeft);
}
else if (mKeyboard->isKeyDown(KC_D) || mKeyboard->isKeyDown(KC_RIGHT)) {
mCharacter->addMovement(Character::DR_StepRight);
}
else if (mKeyboard->isKeyDown(KC_W) || mKeyboard->isKeyDown(KC_UP)) {
mCharacter->addMovement(Character::DR_Forward);
}
else if (mKeyboard->isKeyDown(KC_S) || mKeyboard->isKeyDown(KC_DOWN)) {
mCharacter->addMovement(Character::DR_Backward);
}

betajaen

11-06-2007 13:01:09

That's fine.

Does the character fall through the terrain, or does it rest on top of it?

Leeman

12-06-2007 02:51:08

It fall to the terrain slowly, then rest on the terrain.

Leeman

12-06-2007 03:04:12

by the way, while the body (B2_02_TianJian_HY1.mesh) falling to the terrain (faster than the charactor), it hits the charactor. But this just affect the body (B2_02_TianJian_HY1.mesh) , not the charactor.

Leeman

12-06-2007 11:07:29

en, the character can move! but it move so slowly that i thought that it can't move! I set the "stepoffset" parameter but have no effect.

betajaen

12-06-2007 11:37:29

I just implemented Character on the terrain and it moves at a walking pace. The same pace as it would on the usual flat plane.

kungfoomasta

12-06-2007 23:34:04

Does the nx Character Controller support sliding against walls/objects?

betajaen

13-06-2007 00:13:22

Yep.

HexiDave

17-06-2007 16:29:52

I suppose I'll use this thread to post my question about using the heightfield...

I built my own Shape and ShapeDescription since I don't load from a texture, but already have the heightmap in a readable format, so I wanted to skip all of that. It seems to build it fine, but I can't figure out the placement for it. When you're using SetGlobalPosition(), where is it moving from, the center or a certain corner? That is, where does the 0,0 heightmap position go - is it the point defined by SetGlobalPosition() or is the center pixel of the heightmap the center of the heightfield object?

It's just that I can't seem to figure out how to place the collision mesh since I can't see it and the remote debugger doesn't want to play nicely.


Any insight you can give me would be good - if you need my code, let me know and I'll grab it.

betajaen

17-06-2007 17:18:58

The first vertex of the height map will be at 0,y,0. So if you want it to work with the default Ogre terrain then leave it at 0,0,0.

With any other terrain solutions, then the terrain should be placed at Coords - (heightmapsize.width / 2, 0, heightmapsize.depth / 2).

HexiDave

17-06-2007 17:25:22

I must be doing something wrong then as that should be right where I put it.

I'll check my code, I'm sure it's something I fouled up.

Thanks.