Simulation inaccuracies and resolution

Post Reply
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Simulation inaccuracies and resolution

Post by avithohol »

Dear Community

I have proper frame independent simulation, with proper world scale (1 unit = 1 meter), but the collision is inaccurate.

Slow moving objects are unsteady on first inpact (even with just falling boxes affected only by gravity).

Bit faster objects even miss colllision altogether, and escape geometry (like boxes shot with applyCentralImpulse function with impulse 40 in a forward direction).

Simptons are demonstrated here:
https://youtu.be/BdHnKF5gl_A

I use bullet-2.81-rev2613 version.

Based on documentation: http://bulletphysics.org/mediawiki-1.5. ... D.3D_1_.3F
, I just need to increase the resolution, by passing higher maxSubstep and lower fixedTimeStep parameters,
so instead of this:

Code: Select all

stepSimulation
(
	static_cast<btScalar>(frameTimer.getElapsedSeconds()),	//btScalar timeStep: frameTimer.getElapsedSeconds() returns sensible seconds frame by frame like 0.0164509
	1,														//int maxSubSteps,
	btScalar(1.)/btScalar(60.)								//btScalar fixedTimeStep
);
I may use this:

Code: Select all

stepSimulation
(
static_cast<btScalar>(frameTimer.getElapsedSeconds())	//btScalar timeStep,
10														//int maxSubSteps,
btScalar(1.)/btScalar(240.)								//Funny, but even 1/120 is not enough, and only 1/240 seems to be stable.
);
That high resolution works actually, but my concern is that increasing resolution burden the CPU much more,
and is a total overkill in my case.

My application has no high demand, the 1/60 fixed timestep should be just sufficient, even 1/30.

Reading the docs back and forth, but couldn't pinpoint what else I miss, so any thoughts are appreciated.



More info:
The falling boxes' dimensions are
x 0.5f y 0.5f z 0.5f
in other words, boxes are 1 meter wide, tall, and deep.



Thank you,
A
lunkhound
Posts: 99
Joined: Thu Nov 21, 2013 8:57 pm

Re: Simulation inaccuracies and resolution

Post by lunkhound »

Try turning on the CCD (Continuous Collision Detection) feature for your moving objects. It should prevent them from tunneling through collision geometry.
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Simulation inaccuracies and resolution

Post by avithohol »

lunkhound wrote:Try turning on the CCD (Continuous Collision Detection) feature for your moving objects. It should prevent them from tunneling through collision geometry.
Thanks for the reply.
Correct me if I am wrong, but CCD are computation heavy, and a special case design for extreme moving objects, like gun bullets, missiles, and as such, their numbers should be kept minimum in a simulation.

To overcome my issue I should set all rigidbodies to CCD, but its kind a overkill.

Even a gravity pulled box falling from 1 meter penetrates geometry a bit, hence appears unsteady on impact.
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Simulation inaccuracies and resolution

Post by avithohol »

avithohol wrote:
lunkhound wrote:Try turning on the CCD (Continuous Collision Detection) feature for your moving objects. It should prevent them from tunneling through collision geometry.
I enabled CCD with various thresholds, result is here:
https://youtu.be/RU7uRYVoOmg

Somewhat better, but still unsteady, partially penetrating boxes.

I am thinking about scale up the world, and speed up the simulation,
as i got better results with that,
but is it a recommended step?
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: Simulation inaccuracies and resolution

Post by Typhontaur »

Try to reduce the size of the triangles in the map (chop size)
Example: If the floor is made up of 2 triangles, you can divide it into more triangles.
I had problems with objects instability (like dance) when I had big maps with big triangles ..
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Simulation inaccuracies and resolution

Post by avithohol »

Typhontaur wrote:Try to reduce the size of the triangles in the map (chop size)
Example: If the floor is made up of 2 triangles, you can divide it into more triangles.
I had problems with objects instability (like dance) when I had big maps with big triangles ..

Thanks for the reply.
Unfortunately, it didn't help, I tested dropping box on 1 m wide square, it behaves the same as on the 100 meter wide one.
TonyS
Posts: 10
Joined: Sat May 27, 2017 8:16 am

Re: Simulation inaccuracies and resolution

Post by TonyS »

Have you tried increasing the height of the floor. (below the ground)
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: Simulation inaccuracies and resolution

Post by Typhontaur »

TonyS wrote:Have you tried increasing the height of the floor. (below the ground)
Yes, this and another problem.
Too thin walls are perforated.
But watching the video above, he has sturdy columns, so I do not know ...
I also found that the speed of impact when it is too much, not only crosses the geometries of the map, but 2 objects that collide become like ghosts ...
*sorry, google translator* :)
TonyS
Posts: 10
Joined: Sat May 27, 2017 8:16 am

Re: Simulation inaccuracies and resolution

Post by TonyS »

Are those columns composed of 1 giant quad? Can you turn on the bullet debug view and throw those boxes again? Maybe that is only happening when the box hits the internal edges of the column?
User avatar
Typhontaur
Posts: 135
Joined: Fri Nov 04, 2005 2:22 pm

Re: Simulation inaccuracies and resolution

Post by Typhontaur »

...We must also consider the weight of objects ...
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Simulation inaccuracies and resolution

Post by avithohol »

TonyS wrote:Have you tried increasing the height of the floor. (below the ground)
Thanks for reply.
Yes, i tried with different size of static cuboids as floor too.
All moving geometry penetrates geometry upon impact, but then surface, and relax properly.
Seems to happen regardless of size and shape of the objects.
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Simulation inaccuracies and resolution

Post by avithohol »

Typhontaur wrote:...We must also consider the weight of objects ...
The moving boxes has mass = 1.
avithohol
Posts: 34
Joined: Sun Feb 12, 2017 10:22 am

Re: Simulation inaccuracies and resolution

Post by avithohol »

Interestingly enough, I get more stable simulation if I:
1. Scale up the world by 10 (set gravity to 100 too, boxes become from 1 meter to 10 meter)
as a result, the simulation becomes a slow motion movie, but then
2. Multiply the timeStep by 4.0f when stepping the Simulation

I am pretty sure this is very hackish, and not intended ... but have no idea why it works like this for me.

Code: Select all

btClock physicsTimer;
vUlong previousFrameTime = physicsTimer.getTimeMilliseconds();                          //When was the previous frame time tick

vVoid cPhysicsWorld::stepSimulation(const cApplication* app)
{
	vUlong currentFrameTime = physicsTimer.getTimeMilliseconds();  //Grab the current frame time tick
	vUlong frameInterval = currentFrameTime - previousFrameTime;      //Substract the two to get the interval
	previousFrameTime = currentFrameTime;

	mDynamicsWorld->stepSimulation((float)frameInterval/1000.0f * 4.0f, 10, 1.0f/60.0f);

}

Post Reply