didigw / bullet

Automatically exported from code.google.com/p/bullet
0 stars 0 forks source link

btHeightfieldTerrainShape compatibility with Ogre3D terrain #625

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1.The following code attempts to create a Bullet height field array from an 
Ogre terrain data, but the Ogre vertices are ordered to optimize rendering so 
creates a zig-zag type pattern different to Bullet. 

    _heightfieldData = new float[terrainWidth * terrainLength];

    minHeight = 0x7FFFFFFF;
    maxHeight = 0;

    h = 0;
                pTerrain = mTerrainGroup->getTerrain(0, 0);
                ogreTerrainData = pTerrain->getHeightData();

                for (int v = 0; v < terrainWidth * terrainLength; v++)
                {
                    row = v / terrainWidth + 1;

                    _heightfieldData[h] = ogreTerrainData[v % terrainWidth + (terrainWidth * terrainWidth - row * terrainWidth)];

                    if (_heightfieldData[h] < minHeight)
                    {
                        minHeight = _heightfieldData[h];
                    }
                    else if (_heightfieldData[h] > maxHeight)
                    {
                        maxHeight = _heightfieldData[h];
                    }

                    h++;
                }

    btHeightfieldTerrainShape *groundShape = new btHeightfieldTerrainShape(terrainWidth, terrainLength,
                      _heightfieldData,
                      0,
                      minHeight, maxHeight,
                      1, PHY_FLOAT, false);
    groundShape->setLocalScaling(btVector3(_terrainScale, 1.0f, _terrainScale));
//  groundShape->setUseZigzagSubdivision(true); // new flag added
    _collisionShapes.push_back(groundShape);

What is the expected output? What do you see instead?
The faces of the Ogre terrain mesh don't align with the Bullet faces according 
to debug draw.

What version of the product are you using? On what operating system?
Bullet 2.77 and Bullet 2.80
Windows 7 Pro 64-bit

Please provide any additional information below.
Attached zip file shows a suggested change to Bullet.  A m_useZigzagSubdivision 
bool flag could be added to btHeightfieldTerrainShape to alter how Bullet 
creates collision triangles.

Original issue reported on code.google.com by kll...@havensoftware.com on 12 May 2012 at 12:44

GoogleCodeExporter commented 8 years ago
Sorry also need to initialize the new property in initialize() method.

Original comment by kll...@havensoftware.com on 12 May 2012 at 1:27

Attachments:

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r2566.

Original comment by erwin.coumans on 9 Sep 2012 at 10:48