I am new to this Ogre3d and trying to integrate Sample_Terrain and Physics..
when i try integrating sample_terrain and physics,
I can see the physics body of the terrain but it is flat body ( i mean at elevation part the physics body is not elevated ).
Added code is given below
Code: Select all
// setup the terrain physics:
Vector3 terrainScale( TERRAIN_WORLD_SIZE / ( TERRAIN_SIZE - 1 ), 1, TERRAIN_WORLD_SIZE / ( TERRAIN_SIZE - 1 ) );
float* terrainData = mTerrainGroup->getTerrain( 0, 0 )->getHeightData();
float* heights = new float[ TERRAIN_SIZE * TERRAIN_SIZE ];
// The following works.
// At least boxes stop at this point but keep shaking...
for ( int i = 0; i < (TERRAIN_SIZE-1) * (TERRAIN_SIZE-1); i++ )
terrainData[ i ] = terrainData[ i ] / 128.0f;
// Fix the terrain physics alignment:
for ( int i = 0; i < TERRAIN_SIZE; i++ )
{
memcpy( heights + TERRAIN_SIZE * i, terrainData + TERRAIN_SIZE * (TERRAIN_SIZE-i-1), sizeof(float) * TERRAIN_SIZE );
}
// create a terrain shape from a HeightmapCollisionShape
OgreBulletCollisions::HeightmapCollisionShape* terrainShape = new OgreBulletCollisions::HeightmapCollisionShape(
TERRAIN_SIZE,
TERRAIN_SIZE,
terrainScale,
heights,
true
);
//Create a body for the physics world
OgreBulletDynamics::RigidBody* terrainBody = new OgreBulletDynamics::RigidBody( "Terrain", mWorld );
const float terrainBodyRestitution = 0.1f;
const float terrainBodyFriction = 0.8f;
Ogre::SceneNode* pTerrainNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
terrainBody->setStaticShape(
pTerrainNode,
terrainShape,
terrainBodyRestitution,
terrainBodyFriction,
mTerrainGroup->getTerrain( 0, 0 )->getPosition()
);
mBodies.push_back( terrainBody );
mShapes.push_back( terrainShape );
#define TERRAIN_SIZE 513
hope you can understand my problem from attached file.( i am unable to apply physics at the elevation parts of the Terrain).
At Yellow colour ,physics is fine ,where as at red colour circled place physics is not elevated.
Anybody suggest me where i made mistake. or am i need to do anything else.
Thanks and Regards
Umitum.