Simple chain

Bruno Duarte
Posts: 12
Joined: Mon Sep 03, 2007 3:32 pm

Simple chain

Post by Bruno Duarte »

Hi, i'm new in Bullet, and i am triyng to make a simple chain.

I know that i have to use the btPoint2PointConstraint.
i have made this

Code: Select all

        btVector3 pos;
        btRigidBody* body[6];			//chain object
//***********************************************************************//
	//main object the begin of the chain

	btCollisionShape* boxShape =  new btSphereShape(btScalar(1.));
	
	m_collisionShapes.push_back(boxShape);
    boxShape->setMargin(gCollisionMargin);
		btTransform trans;
		trans.setIdentity();
	

		
	
        pos.setValue(btScalar(0.),btScalar(14.),btScalar(0.));//posiçao do topo da corrente
		trans.setOrigin(pos);
		body[0]=localCreateRigidBody(btScalar(0.),trans,boxShape);

//***********************************************************************//

		
//********************************chain******************************//

	btCollisionShape* sphereShape =  new btSphereShape(btScalar(1.));
//sphere
//***********************************************************************//	

	boxsize=1;
	int i=1;

	for(i=1;i<=1;i++){


		sphereShape->setMargin(gCollisionMargin);

	trans.setIdentity();

	pos.setValue(btScalar(0.),btScalar(14.-i*2*boxsize),btScalar(0.));
	
	trans.setOrigin(pos);
	body[i] = localCreateRigidBody(btScalar(1.),trans,sphereShape);
	   
          btVector3 pivotInA(HALF_EXTENTS,-HALF_EXTENTS,-HALF_EXTENTS);

	  btVector3 pivotInB;
	  pivotInB=body[i]->getCenterOfMassTransform().inverse()(body[i-1]->getCenterOfMassTransform()(pivotInA));
	  

      btTypedConstraint* p2p = new btPoint2PointConstraint(*body[i-1],*body[i],pivotInA,pivotInB); 
	  m_dynamicsWorld->addConstraint(p2p);
	   }
my big problem is this part

btVector3 pivotInB;
pivotInB=body->getCenterOfMassTransform().inverse()(body[i-1]->getCenterOfMassTransform()(pivotInA));


and another question, how can i make the chain act like a chain :) , i mean make the balls (in my case stick together)
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Simple chain

Post by Dirk Gregorius »

The Point2Point constraint assures that a point on A and point on B are coincident. Regarding your question Erwin takes the point on A (which is defined in local coordinates) transformes into in world coordinates and then into local the space of B. Alternatively you can take a point in world coordinates and transform into the local space of both bodies and pass the resulting vectors to the constraint.

Erwin, you might consider using something more expressive then operator() to transform points, e.g. btTransform::Apply( btVector v )...


Regarding you final question I don't understand what you mean? Do you want a totally stiff chain? What is not ok with this chain?

Cheers,
-Dirk
Bruno Duarte
Posts: 12
Joined: Mon Sep 03, 2007 3:32 pm

Re: Simple chain

Post by Bruno Duarte »

When i launch a box in my chain, the balls don't stay together, they stays with a distance among then, i want to make a chain that don't separate the links.

I am going to send my code, it is an adaptation of the appBasicDemo
You do not have the required permissions to view the files attached to this post.
Dirk Gregorius
Posts: 861
Joined: Sun Jul 03, 2005 4:06 pm
Location: Kirkland, WA

Re: Simple chain

Post by Dirk Gregorius »

This is actually typical behaviour for the iterative solver. If you want a "stiffer" chain you need more iterations or a stiff subsolver which Erwin is working on (see Featherstone). Another trick you might try is to scale the inertia tensor artifially be a factor 4 ~ 32...

HTH,
-Dirk
Bruno Duarte
Posts: 12
Joined: Mon Sep 03, 2007 3:32 pm

Re: Simple chain

Post by Bruno Duarte »

Sorry for my dummie, but how can i do that ?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Simple chain

Post by Erwin Coumans »

No, this isn't a problem with the constraint solver in your case, the pivot in A was incorrectly chosen.
Please try to set the pivot in A to be:

Code: Select all

btVector3 pivotInA(0,-HALF_EXTENTS,0);
instead of

Code: Select all

btVector3 pivotInA(HALF_EXTENTS,-HALF_EXTENTS,HALF_EXTENTS);
Hope this helps,
Erwin
You do not have the required permissions to view the files attached to this post.
Bruno Duarte
Posts: 12
Joined: Mon Sep 03, 2007 3:32 pm

Re: Simple chain

Post by Bruno Duarte »

Thank you very much :) , now its working like i wanted