Hi,
I am benchmarking a few physics engine for a coin stacking simulation I am trying to build.
One problem I am having is that once I start staking multiple layers of objects, the coins (I am using a simple cylinder shape) start sinking into each other and warping all over the place.
Here is what I am talking about : (gravity is at (0, 0, -10), all coins have the same mass)
https://gfycat.com/DescriptiveDimwittedFlee
The desired behaviour should look something like this, minus the "bouncing around" (this is using box2d, simulating my coin as rectangles) :
https://gfycat.com/NecessaryUnripeBeaver
You can reproduce this behaviour with the basic sample, (5x5x5 boxes), by adding boxes to the y axis (5x30x5)
Thank you for your help
Simulating coin stacking
- drleviathan
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Simulating coin stacking
My guess is that the coins are interpenetrating upon initialization, so Bullet is trying to use penetration resolution rather than enforcing contact points. I wonder what the dimensions of the coins are and what is their collision margin.
-
- Posts: 3
- Joined: Mon Oct 05, 2015 1:58 pm
Re: Simulating coin stacking
I have the same problem even if the coins are definitely not penetrating upon initialization.
Let me help you help me
If you replace the following part of the function BasicExample::initPhysics() in BasicExample, I observe the same behaviour :
Let me help you help me
If you replace the following part of the function BasicExample::initPhysics() in BasicExample, I observe the same behaviour :
Code: Select all
{
//create a few dynamic rigidbodies
// Re-using the same collision is better for memory usage and performance
btCylinderShape* cylShape = new btCylinderShape(btVector3(2.5f, 0.25f, 2.5f));
m_collisionShapes.push_back(cylShape);
/// Create Dynamic Objects
btTransform startTransform;
startTransform.setIdentity();
btScalar mass(1.f);
//rigidbody is dynamic if and only if mass is non zero, otherwise static
bool isDynamic = (mass != 0.f);
btVector3 localInertia(0,0,0);
if (isDynamic)
{
cylShape->calculateLocalInertia(mass, localInertia);
}
for (int i = 0; i < 30; i++)
{
startTransform.setOrigin(btVector3(
btScalar(0),
btScalar(2+0.75f*i),
btScalar(0)));
createRigidBody(mass, startTransform, cylShape);
}
}
- drleviathan
- Posts: 849
- Joined: Tue Sep 30, 2014 6:03 pm
- Location: San Francisco
Re: Simulating coin stacking
I pasted your modifications into the BasicExample.cpp file and saw the same poor behavior. I then experimented with different numbers and dimensions of the coins and learned that the simulation could succeed if I tried combinations of the following:
(1) increase the thickness of the coins
(2) reduce the number of coins in the stack
(3) reduce the speeds of the coins when they hit (e.g. reduce the gap between them on init and the initial offset the bottom coin)
Within the range of my experimentation I could never get a stable stack of 30 coins but I could get 15 to sometimes work depending on how much of (1) - (3) I used.
(1) increase the thickness of the coins
(2) reduce the number of coins in the stack
(3) reduce the speeds of the coins when they hit (e.g. reduce the gap between them on init and the initial offset the bottom coin)
Within the range of my experimentation I could never get a stable stack of 30 coins but I could get 15 to sometimes work depending on how much of (1) - (3) I used.
-
- Posts: 3
- Joined: Mon Oct 05, 2015 1:58 pm
Re: Simulating coin stacking
So even playing with those values, I still get the very weird cylinder glitching into each other bug.
I tried to do the same kind of thing in blender to see if there was a problem with bullet and cylinders or something, but in blender it works fine :
https://gfycat.com/RightWarmArrowworm
(At least after throwing cpu cycles at it, 240 steps per second, 50 solver iterations)
I am looking to achieve the same kind of results with with blender "c++"
I am now confident there is a way, I just don't know which knobs to turn
I tried to do the same kind of thing in blender to see if there was a problem with bullet and cylinders or something, but in blender it works fine :
https://gfycat.com/RightWarmArrowworm
(At least after throwing cpu cycles at it, 240 steps per second, 50 solver iterations)
I am looking to achieve the same kind of results with with blender "c++"
I am now confident there is a way, I just don't know which knobs to turn
Re: Simulating coin stacking
Why not just do the same thing and change the simulation step size to 1/240 and 50 iterations? Not too difficult to do, and certainly will be faster than blenderLouisLOurson wrote: (At least after throwing cpu cycles at it, 240 steps per second, 50 solver iterations)
I am looking to achieve the same kind of results with with blender "c++"
I am now confident there is a way, I just don't know which knobs to turn