New terrain with bullet?

Kukanani

17-05-2010 19:45:09

Looking at the OgreBullet code I get the impression that OgreBullet still uses the old TerrainSceneManager for creating terrains. Are there plans to update this to the new v1.7 terrain? I have some code that I'm trying out for this sort of thing:

int ogreHeightDataSize = 512; //<<<<512 should be replaced with the terrainSize (NOT worldSize) of your terrain.

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

for(int i = 0; i < ogreHeightDataSize; i++)
{
for(int j = 0; j < ogreHeightDataSize; j++)
{
heights[i + (j * ogreHeightDataSize)] = terrain->getHeightAtWorldPosition((float)i*(terrain->getWorldSize()/ogreHeightDataSize)-terrain->getWorldSize()/2.f, 100.f, (float)j*(terrain->getWorldSize()/ogreHeightDataSize)-terrain->getWorldSize()/2.f);
}
}

btHeightfieldTerrainShape* heightfieldShape = new btHeightfieldTerrainShape(ogreHeightDataSize, ogreHeightDataSize, heights, 1, 0, 20, 1, PHY_FLOAT, false);
heightfieldShape->setLocalScaling(btVector3(1000.f/ogreHeightDataSize, 1, 1000.f/ogreHeightDataSize));

btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btMatrix3x3().getIdentity(), btVector3(0.f, 0.f, 0.f)));

btRigidBody* body = new btRigidBody(0.f, motionState, heightfieldShape, localInertia);
//add the body to the dynamics world
dynamicsWorld->addRigidBody(body);


(the above code is not OgreBullet). Should this work?

Fish

17-05-2010 22:23:48

I don't see any reference to the TSM in OgreBulletCollisions::HeightmapCollisionShape(). Were you looking at the demo code?

-Fish

Kukanani

18-05-2010 00:58:30

Yes, I was looking at the demo. You're right, the TSM is not referenced in HeightmapCollisionShape, but it is used in the demo.

My problem is that I just can't seem to get the right arguments passed to the btHeightfieldTerrainShape - between input scaling, bullet scaling, positioning, world size, terrain size, and the bullet parameters, my terrain never comes out right. So I was looking for some sample code that sets up terrain using variables from Ogre::Terrain instead of TSM.