FriedChicken
20-04-2008 16:48:28
I used Bleeding to simulate hundreds of cubes falling onto the terrain which was generated from heightmap. Although most of the cubes fall and roll on the ground nicely, just a few of them float above or buried into the terrain when coming to rest, which isn't what I want. So I wonder how to fix it.
Here is snapshot.
And here is my code :
And here is my 'terrain.cfg' file:
Here is snapshot.
And here is my code :
Resources::Heightfield* createHeightfield(const std::string& heightmap)
{
Ogre::Image img;
img.load(heightmap, "General");
int w = img.getWidth();
int h = img.getHeight();
Resources::ManualHeightfield mh;
// Nothing of the below helps
//mh.setDefaultMaterial0((NxMaterialIndex)0);
//mh.setDefaultMaterial1((NxMaterialIndex)0);
// Setting both vertical extent and thickness makes the app crash (NxHeightmap creation fails)
//mh.setVerticalExtent(1.0f);
//mh.setThickness(1.0f);
mh.begin(w, h);
// Tesselation direction
bool tessltr = false;
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
short height = img.getColourAt(x, y, 0).r * 32767;
mh.sample(height, tessltr);
}
tessltr = !tessltr;
}
return mh.end(true);
}
...
mSceneMgr->setWorldGeometry("terrain.cfg");
mSceneMgr->setSkyDome(true, "Examples/CloudySky", 5, 8, 500);
mWorld = new World("log: html, time-controller: ogre");
mScene = mWorld->createScene("Main", mSceneMgr, "gravity: 0 -9.8 0, floor: no, renderer: ogre");
mWorld->getSDK()->getFoundationSDK().getRemoteDebugger()->connect("localhost");
Resources::Heightfield* hf = createHeightfield("terrain.png");
NxOgre::ShapeParams sp;
sp.setToDefault();
sp.mFlags |= NX_SF_VISUALIZATION;
mScene->createActor("Terrain", new Terrain(hf, float3(1500.0f, 100.0f, 1500.0f), sp, "centering: xz-above, hole-material: 65535"), Ogre::Vector3(750, -100, 750), "static: yes");
for(int i=0;i<10;i++)
{
for(int j=0;j<10;j++)
{
Body* body = mScene->createBody("cube", new Cube(10), Vector3(0, 0, 0), "model: cube.1m.mesh, scale: 10 10 10", "mass: 10");
body->setGlobalPosition(Ogre::Vector3(150*i, 300, 150*j));
}
}
...
And here is my 'terrain.cfg' file:
# 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=1
# 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