I have a height field specified as an array of unsigned chars. I'm using that height field to successfully render terrain using my own functions. I also had a bvhTriangleMeshShape for collision, and it was working well, but since there are more than 100000 triangles there was a lot of overhead when creating the shape (due to function calls), so I decided to give the HeightfieldShape a try. However, it doesn't seem to like the data I'm sending it.
I tried everything. All the different modes, real maximum height or just a very high number, I checked the demo, read the tutorial, searched in google, everywhere I go I find that I seem to be doing everything correctly, but still the heightfield does not recognize the data. I can scale it, and I can change it into diamond subdivision mode just fine. My stuff collides with it when it hits it. But it's FLAT.
Code: Select all
unsigned char* heightfield = new (unsigned char[mapa.getWidth() * mapa.getHeight()]);
int highest = -999999, j = 0;
for (i = 0; i < NUM_VERTS_X; i++)
for (j = 0; j < NUM_VERTS_Z; j++) {
heightfield[j*NUM_VERTS_X+i] = alturas[(i*NUM_VERTS_Z+j)*3];
if (heightfield[j*NUM_VERTS_X+i] > highest)
highest = heightfield[j*NUM_VERTS_X+i];
}
btHeightfieldTerrainShape* heightfieldShape = new btHeightfieldTerrainShape(mapa.getWidth(), mapa.getHeight(), heightfield, highest, 1, false, false);
heightfieldShape->setLocalScaling(btVector3(TRIANGLE_SIZE,0,TRIANGLE_SIZE));
btCollisionShape* trimeshShape = heightfieldShape;
float mass = 0.f;
btTransform startTransform;
startTransform.setIdentity();
startTransform.setOrigin(btVector3(0,0,0));
btRigidBody* staticBody= localCreateRigidBody(mass, startTransform,trimeshShape);
Any help would be much appreciated.