Can OgreBullet works with new Terrain Component?

hustruan

29-09-2011 17:07:42

hello, I'm new to here. I'm trying to use OgreBullet in my shipgame. But I found there is not enough tutorial about it . especially how to do terrain colision.
I use ogre's new terrain system in components. does anyone konw how to do it.

with the old terrain system, I found some code like these

btVector3 min, max;
collisionShape->getAabb(btTransform::getIdentity(), min, max);
sceneNode = Main::getSingleton().getSceneManager()->getSceneNode("Terrain");
sceneNode->setPosition(BtOgre::Convert::toOgre(min));

I need to find a scenenode called "Terrain", I don't know in TerrainGroup whether it still has terain node?

Cookiezzz

02-10-2011 09:41:47

Hi,
look to the OgreBullet examples.

std::string terrain_cfg("terrain.cfg");
mSceneMgr->setWorldGeometry(terrain_cfg);
Ogre::ConfigFile config;

config.loadFromResourceSystem(terrain_cfg, ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME, "=", true);

unsigned page_size = Ogre::StringConverter::parseUnsignedInt(config.getSetting( "PageSize" ));

Ogre::Vector3 terrainScale(Ogre::StringConverter::parseReal( config.getSetting( "PageWorldX" ) ) / (page_size-1),
Ogre::StringConverter::parseReal( config.getSetting( "MaxHeight" ) ),
Ogre::StringConverter::parseReal( config.getSetting( "PageWorldZ" ) ) / (page_size-1));

Ogre::String terrainfileName = config.getSetting( "Heightmap.image" );

float *heights = new float [page_size*page_size];

Ogre::Image terrainHeightMap;
terrainHeightMap.load(terrainfileName, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);

for(unsigned y = 0; y < page_size; ++y)
{
for(unsigned x = 0; x < page_size; ++x)
{
Ogre::ColourValue color = terrainHeightMap.getColourAt(x, y, 0);
heights[x + y * page_size] = color.r;
}
}

mTerrainShape = new OgreBulletCollisions::HeightmapCollisionShape (
page_size,
page_size,
terrainScale,
heights,
true);

RigidBody *defaultTerrainBody = new RigidBody(
"Terrain",
mWorld);

const float terrainBodyRestitution = 0.1f;
const float terrainBodyFriction = 0.8f;

Ogre::Vector3 terrainShiftPos( (terrainScale.x * (page_size - 1) / 2), \
0,
(terrainScale.z * (page_size - 1) / 2));

terrainShiftPos.y = terrainScale.y / 2 * terrainScale.y;

Ogre::SceneNode* pTerrainNode = mSceneMgr->getRootSceneNode ()->createChildSceneNode ();
defaultTerrainBody->setStaticShape (pTerrainNode, mTerrainShape, terrainBodyRestitution, terrainBodyFriction, terrainShiftPos);

mBodies.push_back(defaultTerrainBody);
mShapes.push_back(mTerrainShape);


Cookiezzz