btGeneric6DofSpringConstraint rotation

Post Reply
Kavarna
Posts: 2
Joined: Mon May 29, 2017 1:35 pm

btGeneric6DofSpringConstraint rotation

Post by Kavarna » Mon Jul 03, 2017 4:58 pm

So, i created a spring constraint, and it moves as I expected, but I don't know how I should activate the rotation for the object
Here is how I created the Constraint.

Code: Select all

	btScalar SpringLength( 3 );
	btScalar PivotOffset( 0 );
	btScalar SpringRange( 7 );

	PlaneShape = new btBoxShape( btVector3( 1, 1, 1 ) );
	btTransform tr;
	tr.setIdentity( );
	tr.setOrigin( btVector3( 0, 0, 0 ) );
	tr.getBasis( ).setEulerYPR( 0, 0, 0 );
	MotionState = new btDefaultMotionState( );
	MotionState->setWorldTransform( tr );
	btRigidBody* pBodyA = new btRigidBody( 1, MotionState, PlaneShape );
	m_pWorld->addRigidBody( pBodyA );

	btTransform frameInA;
	frameInA = btTransform::getIdentity( );
	frameInA.setOrigin( btVector3( 0, 0, 0 ) );

	tr.setIdentity( );
	tr.setOrigin( btVector3( 0, 60 - SpringLength - PivotOffset, 0 ) );
	tr.getBasis( ).setEulerYPR( 0, 0, 0 );

	MotionState = new btDefaultMotionState( );
	MotionState->setWorldTransform( tr );
	BoxShape = new btBoxShape( btVector3( 1, 1, 1 ) );
	btRigidBody* pBodyB = new btRigidBody( 0, MotionState, BoxShape );
	m_pWorld->addRigidBody( pBodyB );

	btTransform frameInB;
	frameInB = btTransform::getIdentity( );
	frameInB.setOrigin( btVector3( PivotOffset, -10, 0 ) );

	btGeneric6DofSpringConstraint * pGen6DOFSpring = new btGeneric6DofSpringConstraint(
		*pBodyA, *pBodyB, frameInA, frameInB, true
	);

	pGen6DOFSpring->setLinearLowerLimit( btVector3(  - SpringRange,  - 0,  - SpringRange ) );
	pGen6DOFSpring->setLinearUpperLimit( btVector3(  + SpringRange,  + 0,  + SpringRange ) );

	pGen6DOFSpring->setAngularLowerLimit( btVector3( - SpringRange, - SpringRange, - SpringRange ) );
	pGen6DOFSpring->setAngularUpperLimit( btVector3( + SpringRange, + SpringRange, + SpringRange ) );

	m_pWorld->addConstraint( pGen6DOFSpring, true );

	for ( int i = 0; i < 3; ++i )
	{
		pGen6DOFSpring->enableSpring( i, true );
		// pGen6DOFSpring->enableSpring( i+3, true );
		pGen6DOFSpring->setStiffness( i, 1 );
		pGen6DOFSpring->setStiffness( i + 3, 1 );
		pGen6DOFSpring->setDamping( i, btScalar( 0.99 ) );
		pGen6DOFSpring->setDamping( i + 3, btScalar( 0.99 ) );
		pGen6DOFSpring->setParam( BT_CONSTRAINT_STOP_CFM, btScalar( (1.0E-5) ), i );
		pGen6DOFSpring->setParam( BT_CONSTRAINT_STOP_CFM, btScalar( ( 1.0E-5 ) ), i + 3 );
		pGen6DOFSpring->setParam( BT_CONSTRAINT_CFM, btScalar( ( 1.0E-5 ) ), i );
		pGen6DOFSpring->setParam( BT_CONSTRAINT_CFM, btScalar( ( 1.0E-5 ) ), i+3 );
	}
	pGen6DOFSpring->setEquilibriumPoint( );
I think I should use enableSpring for 3,4,5 but if I do that, my program stops at this point (btSequentialImpulseConstraintSolver.cpp)

Code: Select all

							btScalar sum = iMJlA.dot(solverConstraint.m_contactNormal1);
							sum += iMJaA.dot(solverConstraint.m_relpos1CrossNormal);
							sum += iMJlB.dot(solverConstraint.m_contactNormal2);
							sum += iMJaB.dot(solverConstraint.m_relpos2CrossNormal);
							btScalar fsum = btFabs(sum);
							btAssert(fsum > SIMD_EPSILON); // Here it stops; iMJlA = btVector3(0,0,0);
							solverConstraint.m_jacDiagABInv = fsum>SIMD_EPSILON?btScalar(1.)/sum : 0.f;
There might be lots of errors in my code, I'm an absolute beginner. Can someone help me, please?

Post Reply