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:
and the terrain.cfg:
and here is the code I expect it move the character:
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);
}