• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Geometrian

Sloped Bullet Heightmap Inaccurate

9 posts in this topic

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

0

Share this post


Link to post
Share on other sites
  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.

0

Share this post


Link to post
Share on other sites
  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.
0

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

  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.

0

Share this post


Link to post
Share on other sites


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
0

Share this post


Link to post
Share on other sites

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
1

Share this post


Link to post
Share on other sites

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

1

Share this post


Link to post
Share on other sites

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

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0