Cange 2.71 -> 2.72 (or svn 1388), broke.. SOLVED

ola
Posts: 169
Joined: Sun Jan 14, 2007 7:56 pm
Location: Norway

Cange 2.71 -> 2.72 (or svn 1388), broke.. SOLVED

Post by ola »

EDIT: Found out the problem: had to set m_shapeType in the constructor instead of implementing the getShapeType function. It works again now.


Hello all,

I just tried an upgrade from 2.71 to 2.72, and then to the newest SVN 1388 version. Something has changed since 2.72 that breaks my terrain collision system, which has been working nicely for the last year and a half.

Our game engine has a huge global dataset for the terrain (similar to Google Earth, maybe), which is pretty optimized. So to get bullet collision into this, I wrote a terrain collision shape:

Code: Select all

class WbBulletTerrain : public btConcaveShape
{
public:

   WbBulletTerrain(GgGlobe* terrain);
   ~WbBulletTerrain();
 
   virtual void  processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
   virtual void  processAllTrianglesBruteForce(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const;
   
   virtual void  getAabb(const btTransform& t,btVector3& aabbMin,btVector3& aabbMax) const;
   virtual void  calculateLocalInertia(btScalar mass,btVector3& inertia) const;
   
   virtual void  setLocalScaling(const btVector3& scaling)  { scaling_ = scaling;             }
   virtual const btVector3& getLocalScaling() const         { return scaling_;                }
   virtual const char* getName() const                      { return "TERRAIN";               }
   virtual int   getShapeType() const                       { return TERRAIN_SHAPE_PROXYTYPE; }
};
processAllTriangles will find the proper terrain triangles inside the provided aabb, and pass them on to the provided callback function. The processAllTrianglesBruteForce just calls processAllTriangles, I didn't quite figure out why there are two functions like this.

On the implementation side, here's the constructor and getAabb functions:

Code: Select all

WbBulletTerrain::WbBulletTerrain(GgGlobe* terrain)
{
   terrain_ = terrain;
   
   scaling_.setValue(btScalar(1.0),btScalar(1.0),btScalar(1.0));
   
   double box = Gg::earth_radius + 10000.0;
   local_aabb_min_.setValue(btScalar(-box), btScalar(-box), btScalar(-box));
   local_aabb_max_.setValue(btScalar( box), btScalar( box), btScalar( box));
}

void WbBulletTerrain::getAabb(const btTransform& trans,btVector3& aabbMin,btVector3& aabbMax) const
{
   btVector3 localHalfExtents = btScalar(0.5)*(local_aabb_max_ - local_aabb_min_);
   btVector3 localCenter = btScalar(0.5)*(local_aabb_max_ + local_aabb_min_);

   btMatrix3x3 abs_b = trans.getBasis().absolute();  

   btPoint3 center = trans(localCenter);

   btVector3 extent = btVector3(abs_b[0].dot(localHalfExtents),
         abs_b[1].dot(localHalfExtents),
        abs_b[2].dot(localHalfExtents));
   extent += btVector3(getMargin(),getMargin(),getMargin());

   aabbMin = center - extent;
   aabbMax = center + extent;
}
The shape bounding box encapsulates the whole earth + mount everest++, and this ensures that every dynamic rigid body should be tested for terrain collision at all times.

When I add this shape to the bullet dynamics world, I create a static rigid body placed at the earth's core, and that's it. It's all been working so far, but not any more. processAllTriangles is not called at all, so my other rigid bodies fall through the ground.

So I'd really appreciate any hints on what did change from bullet 2.71 to 2.72 that might have caused this to stop working. I do use double precision for this (obviously ;-) ), I cannot test in single precision. I use the btDbvtBroadphase, but have tested with the bt32BitAxisSweep3 broadphase too, no difference.

Maybe it's got something to do with the added ccd functionality?

Best regards,
Ola

EDIT: Never mind the brute force function, I found it's been removed from the btConcaveShape.h file anyway.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Cange 2.71 -> 2.72 (or svn 1388), broke.. SOLVED

Post by Erwin Coumans »

Good you found the solution yourself.

We should have made it more clear in the release notes, and make this API change less error-prone for derived classes.

Thanks,
Erwin