Page 1 of 1

How to simulate a conveyor?

Posted: Sun Dec 05, 2010 5:02 pm
by PeterMacGonagan
Hello,

Can you tell me how to simulate a conveyor, please?
Like that: http://www.youtube.com/watch?v=yKGyzcaOuA4&NR=1

Thank you.

Re: How to simulate a conveyor?

Posted: Fri Dec 17, 2010 5:12 pm
by PeterMacGonagan
up, please!
Even a simplified model... I just need that some boxes travel a conveyor.

Re: How to simulate a conveyor?

Posted: Fri Dec 17, 2010 5:57 pm
by bone
Search for motors in Bullet.

Re: How to simulate a conveyor?

Posted: Fri Dec 17, 2010 11:43 pm
by Erwin Coumans
You can use special friction mode, with a target velocity and direction to simulate a conveyor.

Code: Select all

gContactAddedCallback = CustomMaterialCombinerCallback;

///this flag will use the friction information from the contact point, if contactPoint.m_lateralFrictionInitialized==true
m_dynamicsWorld->getSolverInfo().m_solverMode |= SOLVER_ENABLE_FRICTION_DIRECTION_CACHING;

///enable the callback for the ground object
body->setCollisionFlags(body->getCollisionFlags()  | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);

static bool CustomMaterialCombinerCallback(btManifoldPoint& cp,	const btCollisionObject* colObj0,int partId0,int index0,const btCollisionObject* colObj1,int partId1,int index1)
{
	cp.m_lateralFrictionInitialized = true;
	///choose a target velocity in the friction dir1 direction, for a conveyor belt effect
	cp.m_lateralFrictionDir1.setValue(0.5,0.5,0.5);
	cp.m_lateralFrictionDir1.normalize();

	///optionally downscale the friction direction 2 for lower (anisotropic) friction (rather than a unit vector)
	btScalar downscale = 1.f;
	cp.m_lateralFrictionDir2 = downscale*cp.m_lateralFrictionDir1.cross(cp.m_normalWorldOnB);
	
	cp.m_contactMotion1 = 1.f;
	//cp.m_contactCFM2 = 0.1;
	//cp.m_combinedFriction = 10;
	//cp.m_combinedRestitution = calculateCombinedRestitution(restitution0,restitution1);
	return true;
}
See attached BasicDemo.cpp
BasicDemo.zip
Thanks,
Erwin

This was earlier discussed here: also http://www.bulletphysics.org/Bullet/php ... f=9&t=3555

Re: How to simulate a conveyor?

Posted: Sat Dec 18, 2010 4:49 pm
by sparkprime
If you set the velocity of a static object, you'll get the friction you want even though it remains stationary.

Re: How to simulate a conveyor?

Posted: Wed Dec 22, 2010 12:53 pm
by Flix
sparkprime wrote:If you set the velocity of a static object, you'll get the friction you want even though it remains stationary.
Well, it works :D .
This easy trick seems to work for static bodies only. Probably the solution Erwin posted is more generic, although more complex.
Thanks for the tip.

Re: How to simulate a conveyor?

Posted: Wed Dec 22, 2010 4:27 pm
by sparkprime
I think if you use Erwin's suggestion on a dynamic conveyor belt object you might need to include the conveyor belt object's linearVelocity at the contact point in the calculation but not sure.

Re: How to simulate a conveyor?

Posted: Wed Sep 04, 2013 9:28 am
by Gickl
hi,

has someone used the custom friction callback for a dynamic body yet? i would like to implement a box that can be moved over the ground by using custom friction for that box...but if i use the callback posted above like it is the box remains in the start position (even in the air) and nothing happens...

Best regards
Gickl

EDIT: I made a dumb mistake...i applied the collision flags of a different (static) body to the dynamic body when setting the CF_CUSTOM_MATERIAL_CALLBACK flag, so now the callback works