Building a not-moving tree (graph)

corixan
Posts: 1
Joined: Mon Jan 04, 2010 3:30 am

Building a not-moving tree (graph)

Post by corixan »

Hi,
I'm new with Bullet and tried some easy stuff but now I'm stuck with a little tree (graph).
I mean, it works somehow but it doesn't stop moving and there is most likely a better solution for it.
Could someone give me a little hint or idea how to make it better?

Thanks

PS: Sorry if there is already a thread about it but I didn't know what to look for...

Code: Select all

	//variables
		mass = 100.f;
		int iStartHeight=13;
		int iHalfEdgeLenght=5;
		int iNumberOfNodes=3;

		//used shapes
		btCollisionShape* csNode = new btSphereShape(btScalar(1.));
		btCollisionShape* csEdge = new btCylinderShape(btVector3(0.1,(iHalfEdgeLenght-2.5),0));//diameter, height, ???

		//fixed rootnode
		trans.setIdentity();

		trans.setOrigin(btVector3(0,iStartHeight,0));
		btRigidBody* body0 = localCreateRigidBody( 0,trans,csNode);
 
		trans.setIdentity();

		trans.setOrigin(btVector3(0,(iStartHeight-2*iHalfEdgeLenght),1));

		//jointpositions
		btTransform frameIn0, frameIn1, frameInm1;
		frameIn0 = btTransform::getIdentity();
		frameIn0.getBasis().setEulerZYX(0, 0, M_PI_2);
		frameIn0.setOrigin(btVector3(0,0,0));
		frameIn1 = btTransform::getIdentity();
		frameIn1.getBasis().setEulerZYX(0,0,  M_PI_2);
		frameIn1.setOrigin(btVector3(0,(iHalfEdgeLenght),0));
		frameInm1 = btTransform::getIdentity();
		frameInm1.getBasis().setEulerZYX(0,0,  M_PI_2);
		frameInm1.setOrigin(btVector3(0,-(iHalfEdgeLenght),0));

		for(int i=1;i<=iNumberOfNodes;i++)
		{		
			btRigidBody* body1 = localCreateRigidBody(mass,trans,csNode);
			trans.setIdentity();

			trans.setOrigin(btVector3(2*(i-1),(iStartHeight-iHalfEdgeLenght),0));
			btRigidBody* body2 = localCreateRigidBody(mass,trans,csEdge);
			m_dynamicsWorld->addRigidBody(body1);
			if(i==1){body1->setGravity(btVector3(100,0,0));}
			if(i==2){body1->setGravity(btVector3(-100,0,-100));}
			if(i==3){body1->setGravity(btVector3(0,0,100));}


			m_ctc = new btConeTwistConstraint(*body0, *body2, frameIn0, frameIn1);
			m_ctc->setLimit(btScalar(M_PI_4), btScalar(M_PI_4), btScalar(0.));
			//m_ctc->setLimit(btScalar(M_PI_4*0.6f), btScalar(M_PI_4), btScalar(M_PI) * 0.8f, 1.0f); // soft limit == hard limit
			m_dynamicsWorld->addConstraint(m_ctc, true);
			m_ctc = new btConeTwistConstraint(*body2, *body1, frameInm1, frameIn0);
			m_ctc->setLimit(btScalar(M_PI_4), btScalar(0.), btScalar(0.));
			m_dynamicsWorld->addConstraint(m_ctc, true);

			//next layer
			trans.setIdentity();

			trans.setOrigin(btVector3(0,(iStartHeight-2*2*iHalfEdgeLenght),2*i));
			for(int j=1;j<=10;j++)
			{		
				btRigidBody* body3 = localCreateRigidBody(mass,trans,shape);
				trans.setIdentity();

				trans.setOrigin(btVector3(2*(j-1),(iStartHeight-3*iHalfEdgeLenght),2*i));
				btRigidBody* body4 = localCreateRigidBody(mass,trans,csEdge);
				m_dynamicsWorld->addRigidBody(body3);
				body3->setGravity(btVector3(0,-10,0));

				m_ctc = new btConeTwistConstraint(*body1, *body4, frameIn0, frameIn1);
				m_ctc->setLimit(btScalar(M_PI_4), btScalar(M_PI_4), btScalar(0.));
				m_dynamicsWorld->addConstraint(m_ctc, true);
				m_ctc = new btConeTwistConstraint(*body4, *body3, frameInm1, frameIn0);
				m_ctc->setLimit(btScalar(M_PI_4), btScalar(M_PI_4), btScalar(0.));
				m_dynamicsWorld->addConstraint(m_ctc, true);
				trans.setIdentity();

				trans.setOrigin(btVector3(2*j,(iStartHeight-2*2*iHalfEdgeLenght),2*i));
			}
			trans.setIdentity();

			trans.setOrigin(btVector3(2*i,(iStartHeight-2*iHalfEdgeLenght),0));
		}
mako90
Posts: 28
Joined: Tue Jan 05, 2010 12:41 pm

Re: Building a not-moving tree (graph)

Post by mako90 »

Hi,
please read the http://www.continuousphysics.com/ftp/pu ... Manual.pdf carefully and sources for samples on constraints. This is going to solve your problem.

BR.