Bug fix for btAxisSweep3

ole.k
Posts: 17
Joined: Thu Jun 12, 2008 1:32 pm

Bug fix for btAxisSweep3

Post by ole.k »

btAxisSweep3Internal::quantize does not properly implement the clamping of the input point. The point is clamped at first and then scaled and quantized. Due to numerical imprecision, the quantized result may exceed the bounds (m_handleSentinel) for large objects like a btStaticPlaneShape, and the algorithm gets mixed up. Therefore, clamping should be done after scaling:

Code: Select all

340,351c336,343
< 	btPoint3 clampedPoint(point);
< 	
< 
< 
< 	clampedPoint.setMax(m_worldAabbMin);
< 	clampedPoint.setMin(m_worldAabbMax);
< 
< 	btVector3 v = (clampedPoint - m_worldAabbMin) * m_quantize;
< 	out[0] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getX() & m_bpHandleMask) | isMax);
< 	out[1] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getY() & m_bpHandleMask) | isMax);
< 	out[2] = (BP_FP_INT_TYPE)(((BP_FP_INT_TYPE)v.getZ() & m_bpHandleMask) | isMax);
< 	
---
> 	btVector3 v = (point - m_worldAabbMin) * m_quantize;
> 	for (int i = 0; i < 3; i++)
> 	{
> 		out[i] = (v[i] <= 0) ? (BP_FP_INT_TYPE) isMax
> 			: (v[i] >= m_handleSentinel) ? (BP_FP_INT_TYPE) ((m_handleSentinel & m_bpHandleMask) | isMax)
> 			: (BP_FP_INT_TYPE) (((BP_FP_INT_TYPE) v[i] & m_bpHandleMask) | isMax);
> 	}
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bug fix for btAxisSweep3

Post by Erwin Coumans »

Would it be possible to generate a full patch using the latest SVN version, and add it to http://code.google.com/p/bullet/issues/list ?

It makes it easier to apply it using TortoiseSVN or the patch command.
Thanks,
Erwin

By the way, we just applied the inertia tensor computation: http://code.google.com/p/bullet/source/detail?r=1253
ole.k
Posts: 17
Joined: Thu Jun 12, 2008 1:32 pm

Re: Bug fix for btAxisSweep3

Post by ole.k »

Erwin Coumans wrote:Would it be possible to generate a full patch using the latest SVN version, and add it to http://code.google.com/p/bullet/issues/list ?
Yes, I have just done this.
Erwin Coumans wrote:By the way, we just applied the inertia tensor computation: http://code.google.com/p/bullet/source/detail?r=1253
Great, thanks!
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Bug fix for btAxisSweep3

Post by Erwin Coumans »

The bugfix for the clamping/quantization has now be committed,

http://code.google.com/p/bullet/source/detail?r=1345

Thanks a lot for this!
Erwin