Problems with CustomMaterialcombinerCallback

Post Reply
maiklof
Posts: 24
Joined: Wed Nov 20, 2013 10:01 am

Problems with CustomMaterialcombinerCallback

Post by maiklof »

Hi,
I have created the CustomMaterialcombinerCallback and CustomMaterial class in order to be able to simulate conveyor belts. The idea is to attach the custom material object as userpointer on those collision objects I want to behave as conveyors. But I have some issues:
1 - This does not work if I do not set my dynamic objects to never sleep (the boxes I want to move through the conveyors).
2 - Some boxes get stacked and do not move if the conveyor stops for a while. I need to move them a little to get them move again. The contact points seem to be ok in the debugger.
3 - I have seen in the debugger that if the conveyor object is smaller than the moving object, sometimes, all the contact points between the objects are created in the center of the conveyor object, and then it is not possible to move it. When the contact points are created in the vertices (like with big conveyors) it works.

Thanks!

Here is the code, so maybe someone can see the problem. I can add debugger screenshots if it could help.

Code: Select all

#include "LinearMath/btTransform.h"
#include "BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h"
#include "BulletCollision/CollisionDispatch/btCollisionObject.h"
#include "BulletCollision/NarrowPhaseCollision/btManifoldPoint.h"

class  btCustomMaterial{
	// Custom material class. If attached as userpointer to a CollisionObject, it makes possible to modify the contact point behaviour
public:

	btVector3 	m_lateralFrictionDir1; //Lateral friction 1
	btScalar	m_contactMotion1;  //Motion speed for lateral friction 1

	btCustomMaterial()
	{
		m_lateralFrictionDir1.setValue(0.f,0.f,0.f);
		m_contactMotion1 = 0.f;
	}

	void setMotionSpeed (btScalar speed)
	{
		m_contactMotion1 = speed;
	}

	void setMotion (btVector3& direction, btScalar speed)
	{
		m_lateralFrictionDir1 = direction;
		m_contactMotion1 = speed;
	}

};

static bool CustomMaterialCombinerCallback(btManifoldPoint& cp,	const btCollisionObjectWrapper* colObj0Wrap,int partId0,int index0,const btCollisionObjectWrapper* colObj1Wrap,int partId1,int index1)
{
	// Find material to modify cp
	btCustomMaterial* material = NULL;
	// object with custom material
	const btCollisionObject* obj;

	// Check if Object 0 has custom material
	obj = colObj0Wrap->getCollisionObject();
	material = (btCustomMaterial*) obj->getUserPointer();
	if (material != NULL)
	{
		// Motion Friction Speed
		if (material->m_contactMotion1 != 0.0)
		{
			cp.m_lateralFrictionInitialized = true;
			// Motion Friction Direction
			cp.m_lateralFrictionDir1 = quatRotate(obj->getWorldTransform().getRotation(), material->m_lateralFrictionDir1);
			cp.m_contactMotion1 = - material->m_contactMotion1;
			cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
			//Next two lines are necesary to stabilize the cp
			cp.m_lateralFrictionDir1.normalize(); 
			cp.m_combinedFriction = 10;
			return true;
		}
		return false;
	}
	
	// If not, has Object 1 custom material?
	obj = colObj1Wrap->getCollisionObject();
	material = (btCustomMaterial*) obj->getUserPointer();
	if (material != NULL)
	{
		// Motion Friction Speed
		if (material->m_contactMotion1 != 0.0)
		{
			cp.m_lateralFrictionInitialized = true;
			// Motion Friction Direction
			cp.m_lateralFrictionDir1 = quatRotate(obj->getWorldTransform().getRotation(), material->m_lateralFrictionDir1);
			cp.m_contactMotion1 = material->m_contactMotion1;
			cp.m_lateralFrictionDir2 = cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
			//Next two lines are necesary to stabilize the cp
			cp.m_lateralFrictionDir1.normalize(); 
			cp.m_combinedFriction = 10;
			return true;
		}
		return false;
	}
	
    return false;
}
maiklof
Posts: 24
Joined: Wed Nov 20, 2013 10:01 am

Re: Problems with CustomMaterialcombinerCallback

Post by maiklof »

I have still these open issues, can somebody help me please?
NOTE: Curiously if I using "Dantzig" solver it works well, so, is it a bug in the default solver?
teolazza
Posts: 21
Joined: Fri Aug 11, 2017 1:16 pm

Re: Problems with CustomMaterialcombinerCallback

Post by teolazza »

Hi,

I'm exactly in your situation. How have you solved the problem?
Post Reply