GJK with not uniform scaling on rigid convex shape

fred
Posts: 19
Joined: Tue Apr 24, 2007 12:38 pm

GJK with not uniform scaling on rigid convex shape

Post by fred »

Hi,

I'd like to add non uniform scaling support on physic shape in bullet engine. I want to transmit my scaling params to shapes through matrices and not by just scaling physic shapes dimensions. More precisely, I want to support oriented scaling obtained with a matrix concatenation like this one : R-1 . S . R (where R is a Rotation Matrix, R-1 is the inverse matrix of R and S is a scale matrix). So, I think that a simple shape dimensions scaling does not fit ...

Globally, I think that it is possible to adapt the bullet engine with few modifications to handle oriented non uniform scaling. Using change of basis matrix, from world space to shape local space and from local shape space to world space, may be sufficient ...

I checked G. Van Den Bergen's Solid library (that supports non uniform scaling). I’ve found something that I don’t understand. In the penetration depth computation (using support mapping), the "DT_Transform::support" method allows to manage scaled shapes.


class DT_Transform : public DT_Convex {

...

virtual MT_Point3 support(const MT_Vector3& v) const
{
return m_xform(m_child.support(v * m_xform.getBasis()));
}

...


It seems that "v * m_xform.getBasis()" performs a basis change on "v" from world space to shape space.
But this operation is a ‘vector * matrix33’ operation that corresponds to a ‘transposed_matrix33 * vector’ operation. It seems a little strange to me.
The “m_xform.getBasis()” can be scaled and, in these cases, it is not orthogonal. So, it is not a valid inverse matrix in these cases !

Instead of that, I would have used an actual inverse matrix in the following way :

MT_Matrix3x3 base = m_xform.getBasis();
MT_Matrix3x3 inverted_base = base.inverse();
MT_Vector3 v_in_shape_space = inverted_base * v;

But, even without using an inverse matrix, it seems to work well in Solid Lib demo !!!
I don't understand why ! Could somebody explain this to me ??

Thank you in advance !
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: GJK with not uniform scaling on rigid convex shape

Post by Erwin Coumans »

Bullet supports non-uniform local scaling for most collision shapes, but it sounds you need such non-uniform scaling at arbitrary orientations.

There are several ways to implement this, but you should do this on the collision shape level. There is no (easy) way to add scaling in the world transform, the entire engine assumes that the rigid body world transform is a rigid transform without scaling.

One way you could try is to use btUniformScalingShape as a starting point (Bullet\src\BulletCollision\CollisionShapes\btUniformScalingShape.*). Just replace the scalar by a btVector3, and add the rotation before/after all the methods that access the scaling factor. This will probably work fine, but the inertia tensor won't be properly oriented this way, but that is likely not a problem. Otherwise, adding non-uniform scaling to the btCompoundShape, and use the convex shape as child shape, is an option. This method will be more complicated, because all generated contacts have to be transformed back using the inverse non-uniform scaling.

Hope this helps,
Erwin