problems setting up btHingeConstraints

thergothon
Posts: 3
Joined: Mon Mar 01, 2010 12:35 am

problems setting up btHingeConstraints

Post by thergothon »

Okay, basically I have two capsules aligned along their local y-axis, and I want to join them with a hinge joint aligned with their local x axis. The problem is that as soon as I create the joint the simulation starts generating NaN. I think the problem is that I just don't understand what the parameters I'm passing to the constructor are supposed to look like. Anyway the code essentially looks like this:

Code: Select all


    //capsuleA/B are just objects containing a rigid body and capsule collisionShape
    btVector3 posA(0.0f, -capsuleA->length()*0.5f, 0.0f);
    btVector3 posB(0.0f, capsuleB->length()*0.5f, 0.0f);

    btVector3 axisA(1.0f, 0.0f, 0.0f);
    btVector3 axisB(1.0f, 0.0f, 0.0f);

    new btHingeConstraint(*capsuleA->body(), *capsuleB->body(), posA, posB, axisA, axisB);

Any help or suggestions would be greatly appreciated.
thergothon
Posts: 3
Joined: Mon Mar 01, 2010 12:35 am

Re: problems setting up btHingeConstraints

Post by thergothon »

Been a bit distracted with other things, but I've just done some more digging around and it appears that the joint breaks during the simulation step, so I'm guessing the initial parameters are okay. Now I'm wondering if it has something to do with the way I'm setting limits.

Can someone explain what the softness, biasfactor and relaxation values represent in the setLimit call? I can't find any documentation on them anywhere.
User avatar
rponomarev
Posts: 56
Joined: Sat Mar 08, 2008 12:37 am

Re: problems setting up btHingeConstraints

Post by rponomarev »

Hello,

Looks like something is wrong with the initial hinge setup.
To understand what happens I need to know where the bodies are placed,
how they are oriented. Hinge counstructor uses these parameters to build constraint frames.
Could you please post your setup code, like:

Code: Select all

		btTransform tr;
		tr.setIdentity();
		tr.setOrigin(btVector3(btScalar(-20.), btScalar(-2.), btScalar(0.)));
		btRigidBody* pBodyA = localCreateRigidBody( 1.0f, tr, shape);
		pBodyA->setActivationState(DISABLE_DEACTIVATION);
		// dynamic bodyB:
		tr.setIdentity();
		tr.setOrigin(btVector3(btScalar(-30.), btScalar(-2.), btScalar(0.)));
		btRigidBody* pBodyB = localCreateRigidBody(1.0, tr, shape);
		pBodyB->setActivationState(DISABLE_DEACTIVATION);
		// add some data to build constraint frames
		btVector3 axisA(0.f, 1.f, 0.f); 
		btVector3 axisB(0.f, 1.f, 0.f); 
		btVector3 pivotA(-5.f, 0.f, 0.f);
		btVector3 pivotB( 5.f, 0.f, 0.f);
		spHingeDynAB = new btHingeConstraint(*pBodyA, *pBodyB, pivotA, pivotB, axisA, axisB);
		spHingeDynAB->setLimit(-SIMD_HALF_PI * 0.5f, SIMD_HALF_PI * 0.5f);
		// add constraint to world
		m_dynamicsWorld->addConstraint(spHingeDynAB, true);
This will help me to find a problem

About other constraint parameters:
softness is not used by current version of solver;
biasFactor works as a multiplier to constraint error, constraint becomes more "soft" when this factor is close to zero;
relaxation used to control bounce on limits : 1.0 means full bounce, 0.0 means no bounce

Thanks,
Roman