I've searched around the internet to find a way that I can apply bullet collision on Ogre terrain, but I can't find any way.
I've tried to create btHeightfieldTerrainShape for Ogre terrain, but I failed miserably So I decide to make a separate thread that focus on this.
Some recommend using btBvhTriangleMeshShape instead. I also see Bullet example use btBvhTriangleMeshShape to form their terrain.
Ok, if I can't use btHeightfieldTerrainShape, then I'll use btBvhTriangleMeshShape instead But I don't understand much about Ogre 2.1 terrain. How can I get the full form of Ogre's terrain so I can form the bullet collision for Ogre's terrain. I really have the feeling that m_terrainCells & m_heightMap may give me the information I need, but I still can't find any way.
[2.1] Ogre 2.1 Terrain and Bullet Physic terrain
-
- Gremlin
- Posts: 152
- Joined: Sat Aug 12, 2017 4:16 pm
- x 4
- dark_sylinc
- OGRE Team Member
- Posts: 5299
- Joined: Sat Jul 21, 2007 4:55 pm
- Location: Buenos Aires, Argentina
- x 1280
- Contact:
Re: [2.1] Ogre 2.1 Terrain and Bullet Physic terrain
Without knowing anything about Bullet, it would seem it will work by just doing the following:
minHeight and maxHeight you will have to calculate them by iterating over all float values in terra.getHeightmapVec and retrieving the min and max height.
As for flipQuadEdges, that is trial and error. If things don't align with true, then it must be set to false.
Also watch out that physics may be rotated (e.g. 90° rotated) or mirrored (e.g. Z = 100 is Z = -100 for physics).
In order to fix that issue just calibrate your terrain using a 4x4 heightmap with special values at one corner; and placing a few objects randomly. With these things you must try things yourself and fix them. Trial and error.
Code: Select all
heightfieldShape = new btHeightfieldTerrainShape( terra.getWidth(), terra.getDepth(), &terra.getHeightmapVec()[0], terra.getHeight(), minHeight, maxHeight, upAxis = 1, PHY_FLOAT, flipQuadEdges );
heightfieldShape->setLocalScaling( btVector3( terra.getXZDimensions().x, 1, terra.getXZDimensions().z ) );
heightfieldShape->setUseZigzagSubdivision( true ); //should be true or false?
heightfieldShape->setUseDiamondSubdivision( false );
As for flipQuadEdges, that is trial and error. If things don't align with true, then it must be set to false.
Also watch out that physics may be rotated (e.g. 90° rotated) or mirrored (e.g. Z = 100 is Z = -100 for physics).
In order to fix that issue just calibrate your terrain using a 4x4 heightmap with special values at one corner; and placing a few objects randomly. With these things you must try things yourself and fix them. Trial and error.