weird scale dependency for constraint stiffness

jportway
Posts: 2
Joined: Tue Apr 14, 2009 10:40 am

weird scale dependency for constraint stiffness

Post by jportway »

I'm using the JBullet port of bullet, and I understand that there are probably differences between the two, but I'm presuming that the fundamental algorithms must be the same and since there doesn't seem to be a forum for JBullet I'm afraid I'm forced to post here...please humour me...

I'm trying to build a system whereby rigid bodies (I'm using them as particles, really) are constrained to the surface of a sphere. I'm doing this using spherical rigid bodies for the particles and a point2point constraint where the constrained point is offset so that it's attached to a fixed body at the centre of the sphere - the idea is that this then acts like a kind of invisible pendulum with the rigid body attached to the end.

The problem I'm seeing is the stiffness of the constraint seems to be weirdly dependant on the size of the collision shape of the body. In all cases the radius of the sphere I'm constraining to (in other words the offset of the constraint point from the actual rigid body itself) is 1500. Using a particle with radius 1 (a sphereShape collision shape with radius 1) results in an extremely floppy constraint, having very little effect at all. If I change the radius of the collision shape to be 10 it's much stiffer and seems to work pretty well.

On my first attempt at doing this I was using very small numbers - the radius of the sphere to which the particles were constrained was 1.5 and the radius of the particles themselves was about 0.01. This resulted in the constraints basically not working at all. When I scaled up the numbers things seemed to be more successful - but I'm baffled as to why Bullet should care what scale of numbers I use. I understand there are constants used for collision margins etc., but this problem doesn't have anything to do with collisions. The only place I can see that the scale of the rigid body might affect the constraint calculation is in the local inertia calculation, which I have to admit I don't really understand.

I couldn't find any documentation for the "tau" parameter of a constraint, but looking at the source it seems to scale the impulse response, so I assume it sets the stiffness? In any case I've tried adjusting it, and it seems to help slightly, but even with tau set to 0.99 i'm still not getting properly stiff constraints with small particles.

Am I doing something wrong? Maybe using a constraint with a point so far offset from the actual rigid body is a problem? Could this be a bug in JBullet?

any help gratefully received....
jportway
Posts: 2
Joined: Tue Apr 14, 2009 10:40 am

Re: weird scale dependency for constraint stiffness

Post by jportway »

If it helps, here's my setup code (extracted from several classes, so probably won't run as it is)

Code: Select all

dynamicsWorld = new DiscreteDynamicsWorld(dispatcher, overlappingPairCache, solver, collisionConfiguration);

originBody = new RigidBody(0, null, null);
dynamicsWorld.addRigidBody(originBody);

bulletTransform = new Transform();
bulletTransform.setIdentity();
bulletTransform.origin.set(x, y, z);

CollisionShape collisionShape = new SphereShape(particleRadius);

float mass = 1;

Vector3f localInertia = new Vector3f(0, 0, 0);
collisionShape.calculateLocalInertia(mass, localInertia);
RigidBodyConstructionInfo rbInfo = new RigidBodyConstructionInfo(mass, this, collisionShape, localInertia);
rigidBody = new RigidBody(rbInfo);

Vector3f vectToOrigin = new Vector3f();
rigidBody.getCenterOfMassPosition(vectToOrigin);
Vector3f originPosition = new Vector3f();
originBody.getCenterOfMassPosition(originPosition);
vectToOrigin.sub(originPosition);
vectToOrigin.negate();
constraint = new Point2PointConstraint(rigidBody, originBody, vectToOrigin, originPosition);


dynamicsWorld.addRigidBody(rigidBody);
dynamicsWorld.addConstraint(constraint, true);