Sloped Bullet Heightmap Inaccurate

Started by
8 comments, last by Steve_Segreto 10 years, 11 months ago

Hi,

I can create a Bullet heightmap and collide with it. The results generally seem to be correct (large scale features are there). To test, I drop some objects in random places and have a look.

A perfectly flat heightmap is collided perfectly (of any height, as long as it's constant).

However, if the heightfield is sloped, objects penetrate a surprisingly far distance (seemingly related to the slope at that point).

For completeness, how the heightfield is made:


float scale[3] = {1.0f,1.0f,1.0f};
 
//create and fill data
 
btHeightfieldTerrainShape* new_shape = new btHeightfieldTerrainShape(data_size[0],data_size[1], data, 1.0f, 0.0f,scale[1], 1, PHY_FLOAT, true);
new_shape->setLocalScaling(btVector3(scale[0],1.0f,scale[2]));

offset[0] = scale[0]*data_size[0] * 0.5f;
offset[1] = scale[1]              * 0.5f;
offset[2] = scale[2]*data_size[1] * 0.5f;
 
//translate heightmap's associated body to "offset", thus
//putting one corner of the heightmap at the origin.

Here's a screenshot from underneath a heightmap of some cubes falling on it. Notice that the cubes penetrate about 10% to 20% of their depth in!
image1go.png

Thanks,

-G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Advertisement
  1. Have you tried to debug draw boxes as well, or that's already it?
  2. Is your timestep small enough?
  3. There's penetration value, maybe it's too high?

Either way, this kind of question would be better to post on Bullet forums.

  1. Haven't tried debug draw (I was going to try, but it was going to be a pain to set up). The fact that the heightmap works for horizontal collisions seems to suggest that the geometry is at least correct. It just occurred to me that perhaps a tiny shift in either x, z direction could cause the problem. I'll look into possible errors--does the above code look okay for shifting?
  2. 1/60 of a second, with 10 maximum substeps
  3. I don't know anything about this, although it should be noted that, again, the boxes collide perfectly on the constant horizontal section.
  4. Bullet Physics forums appears totally dead.

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

After looking around, I found a reference to a resource that suggested that the map needed to be a power of two plus one (i.e. 2^n+1), since something internally subtracts off the one again. While I have not found the 2^n part to be necessary, instead calculating the offset like so:


offset[0] = scale[0]*(data_size[0]-1) * 0.5f;
offset[1] = scale[1]                  * 0.5f;
offset[2] = scale[2]*(data_size[1]-1) * 0.5f;

. . . fixes the problem. Thanks for the ideas,
-G

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

  1. Bullet Physics forums appears totally dead.

There were 4 posts in the support forum on 14 May - not sure how that counts as totally dead.

By the way, collision of convex shapes against the heightfield is extremely slow (though I'm using 2.79), because whilst it does an AABB check of the convex against the heightfield, if that passes (which it generally will if your shape is near the surface) it goes on to do the full test against all the heightmap triangles in that block - even if they're way underneath your shape. or something like that. I put in an extra test to speed things up.


1. Bullet Physics forums appears totally dead.

There were 4 posts in the support forum on 14 May - not sure how that counts as totally dead.


You're right; I wish I hadn't phrased it that way. I said this because the last time anyone replied to anything I asked there was early 2012. Just because no one seems to have answers for me there nowadays doesn't mean it's dead to everyone.

By the way, collision of convex shapes against the heightfield is extremely slow (though I'm using 2.79), because whilst it does an AABB check of the convex against the heightfield, if that passes (which it generally will if your shape is near the surface) it goes on to do the full test against all the heightmap triangles in that block - even if they're way underneath your shape. or something like that. I put in an extra test to speed things up.

Using 2.81 version. It seems to be fast enough for my purposes (about a hundred objects falling on it at once as a demonstration/proof-of-concept). I'll keep that in mind though. Maybe commit your extra test upstream?

[size="1"]And a Unix user said rm -rf *.* and all was null and void...|There's no place like 127.0.0.1|The Application "Programmer" has unexpectedly quit. An error of type A.M. has occurred.
[size="2"]

Using 2.81 version. It seems to be fast enough for my purposes (about a hundred objects falling on it at once as a demonstration/proof-of-concept). I'll keep that in mind though. Maybe commit your extra test upstream?

I just moved to 2.81, and noticed that there's still the same problem. Here's the modification that does the early out (it makes a really significant difference in my app - which is running on mobile devices so I need to get all the performance I can):

EDIT: Obviously this tweak is customised for my application which has z-up!


 
void btConvexTriangleCallback::processTriangle(btVector3* triangle,int partId, int triangleIndex)

{

  const btCollisionObject* ob = const_cast<btCollisionObject*>(m_triBodyWrap->getCollisionObject());
  //aabb filter NOT is already applied!
  // Quick check on AABB

  const btTransform& tr = ob->getWorldTransform();

  if (

    triangle[0].getZ() < m_aabbMin.getZ() &&

    triangle[1].getZ() < m_aabbMin.getZ() &&

    triangle[2].getZ() < m_aabbMin.getZ()

    )

  {

    return;

  }
 

In addition there are some redundant calls to getVertex in btHeightfieldTerrainShape::processAllTriangles, which I've removed, but which will be insignificant!

@MrRowl - nice trick! The btHeightfieldTerrainShape is a concave shape though.

class btHeightfieldTerrainShape : public btConcaveShape

@MrRowl - nice trick! The btHeightfieldTerrainShape is a concave shape though.

I'm not sure what you're getting at...

It is a concave shape, but still btConvexTriangleCallback ends up getting called. Making this change can improve the frame rate of my app from around 15 to 25 FPS on lower-end mobile devices.

@MrRowl - nice trick! The btHeightfieldTerrainShape is a concave shape though.

I'm not sure what you're getting at...

It is a concave shape, but still btConvexTriangleCallback ends up getting called. Making this change can improve the frame rate of my app from around 15 to 25 FPS on lower-end mobile devices.

Hehe - I guess I need to go back and take a second look. I didn't expect concave shapes to end up in convex callbacks, but like I said I didn't look very deep. I still think its a good mod that you made (it was a compliment - not sarcasm). I had the same frame rate drop and I ended up just reducing the size of the heightmap to just the few height points around the player rather than the whole map.

This topic is closed to new replies.

Advertisement