Page 1 of 1

Simulation inaccuracies and resolution

Posted: Sun Jun 11, 2017 7:59 pm
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

Re: Simulation inaccuracies and resolution

Posted: Mon Jun 12, 2017 10:49 pm
by lunkhound
Try turning on the CCD (Continuous Collision Detection) feature for your moving objects. It should prevent them from tunneling through collision geometry.

Re: Simulation inaccuracies and resolution

Posted: Tue Jun 13, 2017 7:54 pm
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.

Re: Simulation inaccuracies and resolution

Posted: Tue Jun 13, 2017 9:38 pm
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?

Re: Simulation inaccuracies and resolution

Posted: Tue Jun 13, 2017 11:01 pm
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 ..

Re: Simulation inaccuracies and resolution

Posted: Wed Jun 14, 2017 6:55 am
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.

Re: Simulation inaccuracies and resolution

Posted: Wed Jun 14, 2017 7:05 am
by TonyS
Have you tried increasing the height of the floor. (below the ground)

Re: Simulation inaccuracies and resolution

Posted: Wed Jun 14, 2017 8:09 am
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* :)

Re: Simulation inaccuracies and resolution

Posted: Wed Jun 14, 2017 8:24 am
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?

Re: Simulation inaccuracies and resolution

Posted: Wed Jun 14, 2017 8:27 am
by Typhontaur
...We must also consider the weight of objects ...

Re: Simulation inaccuracies and resolution

Posted: Wed Jun 14, 2017 1:45 pm
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.

Re: Simulation inaccuracies and resolution

Posted: Wed Jun 14, 2017 1:47 pm
by avithohol
Typhontaur wrote:...We must also consider the weight of objects ...
The moving boxes has mass = 1.

Re: Simulation inaccuracies and resolution

Posted: Sat Jun 24, 2017 9:46 am
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);

}