Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Sloped Bullet Heightmap Inaccurate


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 Geometrian   Crossbones+   -  Reputation: 1582

Like
0Likes
Like

Posted 14 May 2013 - 02:10 PM

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


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.

Sponsor:

#2 Zaoshi Kaba   Crossbones+   -  Reputation: 4432

Like
0Likes
Like

Posted 14 May 2013 - 03:53 PM

  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.



#3 Geometrian   Crossbones+   -  Reputation: 1582

Like
0Likes
Like

Posted 14 May 2013 - 03:59 PM

  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.

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.

#4 Geometrian   Crossbones+   -  Reputation: 1582

Like
0Likes
Like

Posted 14 May 2013 - 05:59 PM

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


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.

#5 MrRowl   Crossbones+   -  Reputation: 1602

Like
0Likes
Like

Posted 17 May 2013 - 11:13 AM

  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.



#6 Geometrian   Crossbones+   -  Reputation: 1582

Like
0Likes
Like

Posted 17 May 2013 - 01:23 PM


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?

Edited by Geometrian, 17 May 2013 - 01:24 PM.

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.

#7 MrRowl   Crossbones+   -  Reputation: 1602

Like
1Likes
Like

Posted 19 May 2013 - 02:16 PM

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!
 


Edited by MrRowl, 23 May 2013 - 02:39 AM.


#8 Steve_Segreto   Crossbones+   -  Reputation: 1541

Like
0Likes
Like

Posted 23 May 2013 - 12:57 AM

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

 

class btHeightfieldTerrainShape : public btConcaveShape



#9 MrRowl   Crossbones+   -  Reputation: 1602

Like
1Likes
Like

Posted 23 May 2013 - 02:41 AM

@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.



#10 Steve_Segreto   Crossbones+   -  Reputation: 1541

Like
0Likes
Like

Posted 23 May 2013 - 11:18 AM

@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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS