individual anchor influence control [EDIT: patch attached]

gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

individual anchor influence control [EDIT: patch attached]

Post by gjaegy »

Hi,

I need to control the influence of individual anchors. Actually, I need to have hard and soft anchors, and also I need to temporary deactivate some of them (so, influence= 0), and re-activate them later on.

Therefore, I think what I would need is the ability to control the influence of each anchor...

I don't think this would be a big change - I am pretty sure I can do it in an hour.

However, I don't want to use a customized version of Bullet, but would prefer sticking to the standard unmodified version (easier upgrade).

Would that be something that could be integrated into the main trunk ? I could eventually submit you the patch for that, if you agree with this idea...

cheers,
Greg

[EDIT]: below the DIFF for what I changed on my side. I would be glad if it were add into the main trunk ;)
there is only one additional multiplication per anchor and per frame, I don't think this should make a big performance difference...

Code: Select all

Index: btSoftBody.cpp
===================================================================
--- btSoftBody.cpp	(revision 2265)
+++ btSoftBody.cpp	(working copy)
@@ -357,14 +357,14 @@
 
 //
 
-void			btSoftBody::appendAnchor(int node,btRigidBody* body, bool disableCollisionBetweenLinkedBodies)
+void			btSoftBody::appendAnchor(int node,btRigidBody* body, bool disableCollisionBetweenLinkedBodies,btScalar influence)
 {
 	btVector3 local = body->getWorldTransform().inverse()*m_nodes[node].m_x;
-	appendAnchor(node,body,local,disableCollisionBetweenLinkedBodies);
+	appendAnchor(node,body,local,disableCollisionBetweenLinkedBodies,influence);
 }
 
 //
-void			btSoftBody::appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies)
+void			btSoftBody::appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies,btScalar influence)
 {
 	if (disableCollisionBetweenLinkedBodies)
 	{
@@ -379,6 +379,7 @@
 	a.m_body			=	body;
 	a.m_local			=	localPivot;
 	a.m_node->m_battach	=	1;
+	a.m_influence = influence;
 	m_anchors.push_back(a);
 }
 
@@ -2765,7 +2766,7 @@
 		const btVector3		va=a.m_body->getVelocityInLocalPoint(a.m_c1)*dt;
 		const btVector3		vb=n.m_x-n.m_q;
 		const btVector3		vr=(va-vb)+(wa-n.m_x)*kAHR;
-		const btVector3		impulse=a.m_c0*vr;
+		const btVector3		impulse=a.m_c0*vr*a.m_influence;
 		n.m_x+=impulse*a.m_c2;
 		a.m_body->applyImpulse(-impulse,a.m_c1);
 	}
Index: btSoftBody.h
===================================================================
--- btSoftBody.h	(revision 2265)
+++ btSoftBody.h	(working copy)
@@ -274,6 +274,7 @@
 		Node*					m_node;			// Node pointer
 		btVector3				m_local;		// Anchor position in body space
 		btRigidBody*			m_body;			// Body
+		btScalar				m_influence;
 		btMatrix3x3				m_c0;			// Impulse matrix
 		btVector3				m_c1;			// Relative anchor
 		btScalar				m_c2;			// ima*dt
@@ -745,8 +746,8 @@
 
 	/* Append anchor														*/ 
 	void				appendAnchor(	int node,
-		btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false);
-	void			appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false);
+		btRigidBody* body, bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1);
+	void			appendAnchor(int node,btRigidBody* body, const btVector3& localPivot,bool disableCollisionBetweenLinkedBodies=false,btScalar influence = 1);
 	/* Append linear joint													*/ 
 	void				appendLinearJoint(const LJoint::Specs& specs,Cluster* body0,Body body1);
 	void				appendLinearJoint(const LJoint::Specs& specs,Body body=Body());
gjaegy
Posts: 178
Joined: Fri Apr 18, 2008 2:20 pm

Re: individual anchor influence control [EDIT: patch attache

Post by gjaegy »

up
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: individual anchor influence control [EDIT: patch attache

Post by Erwin Coumans »

The patch (Issue 502) has been applied in latest trunk:

Thanks for the contribution!
Erwin