[Solved] Object jittering (again)

User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

[Solved] Object jittering (again)

Post by dotsquid »

Hello.
I've tried to find the solution of the jittering problem, but no luck.
The problem is that the object which simply moves up by the force is jittering. The object is quite big - its linear size is about 2.5 - 3 meters (so it's not the problem of the small objects). Normally I'm using a variable timeStep calculating it as a difference between TimeGetTime() get on serial frames. But when I tried a fixed timeStep equal to 1.0f / 60.0f, the jittering disappeared. However, I still want to have a variable timeStep.
Any ideas what's wrong and what to do?
Last edited by dotsquid on Fri Sep 16, 2011 2:10 pm, edited 1 time in total.
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Object jittering (again)

Post by Mako_energy02 »

By variable timestep, do you mean the third parameter of your StepSimulation() call is variable? Or the first?

In the case of the third param being variable, there is nothing you really can do. Constantly incrementing by erratic rates will cause the solvers internal to bullet constantly come up with different values which will tamper with the simulation in later steps. Essentially it makes the entire simulation unstable and not deterministic. You really, really shouldn't be doing that.

If instead you mean the first param...then that's a bit more of a head scratcher. As the first param is meant to be variable.
User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

Re: Object jittering (again)

Post by dotsquid »

I mean the first parameter.
That's why I've asked the help here. My head will bleed soon due to that scratching :(
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Object jittering (again)

Post by Erwin Coumans »

You need to provide us with a reproduction case, preferably modifying the BasicDemo so we can reproduce the result and see if we can help improving it.

You can attach a zip files in this forum.
Thanks,
Erwin
User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

Re: Object jittering (again)

Post by dotsquid »

Hi.
I've managed to modify the BasicDemo to reproduce the jittering issue. But it seems on some machines jittering is not very noticable. However one of the machines showed a "perfect" jittering when the mouse was being dragged.
PS. I'm not familiar with CMake very well, so maybe I've done something wrong.

Thanks in advance.
You do not have the required permissions to view the files attached to this post.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Object jittering (again)

Post by Erwin Coumans »

The object is freely flying in the air, not in a resting state. I don't notice any jitter.

On what machine do you get jitter? Could it just be a rendering/camera issue?
Does the jitter also happen when the camera is static (#define DISABLE_CAMERA 1) ?
If so, the camera should track the interpolated motionstate of the cube, not the rigidbody->getWorldTransform.

Another thing to try is to apply the force in a pre-tick callback, see
http://bulletphysics.org/mediawiki-1.5. ... _Callbacks

Thanks!
Erwin
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Object jittering (again)

Post by mi076 »

looked at it... Replaced line
cube->applyCentralForce(btVector3(0.0f, btSin(timeGetTime() * 0.001f) * 125.f + 75.f, 0.0f));
with
cube->applyCentralForce(btVector3(0.0f, 100.0f, 0.0f));

and cube is going up smooth like butter..... ??
Last edited by mi076 on Fri Sep 09, 2011 7:47 pm, edited 1 time in total.
User avatar
Garibalde
Posts: 44
Joined: Fri Dec 18, 2009 6:06 pm
Location: Montreal

Re: Object jittering (again)

Post by Garibalde »

Hi

I had similar issue. However mine was two-fold. First the timestep that was used (dt) in the stepsimulation() routine was coming from my frame render loop. I found that this was not very stable from iteration to iteration causing sudden jumps in the timestep. I smoothen this out with a timestep controller for dt prior to the stepsimulation call, that keeps it constant and smooth. This greatly helped the jitter.

Secondly, However over time stacked objects will fall over from the jitter still. This was due to the fact that switching kinematic objects to dynamics and back to kinematics was not correctly done and those dynamic object returned from kinematics would never sleep, therefore small jitter overtime causes the stacked objects to become unstable. Check the isActive() of all the bodies in the simulation to make sure they do sleep after a while if you encounter this problem. I was using Wants_deactivation/disable_activation to take objects out of the dynamics when switching to kinematics and when returned does not correctly sleep the object anymore. I fixed this also in the thread below

http://www.bulletphysics.org/Bullet/php ... f=9&t=4517

Hope this helps
User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

Re: Object jittering (again)

Post by dotsquid »

Erwin Coumans wrote:On what machine do you get jitter? Could it just be a rendering/camera issue?
Does the jitter also happen when the camera is static (#define DISABLE_CAMERA 1) ?
If so, the camera should track the interpolated motionstate of the cube, not the rigidbody->getWorldTransform.

Another thing to try is to apply the force in a pre-tick callback, see
http://bulletphysics.org/mediawiki-1.5. ... _Callbacks

Thanks!
Erwin
Erwin,
I get jiitering on my Intel i5-2400. Also it was seen on i7-860 and Core2Duo E6600 @ 2.4GHz. I don't think it's a rendering issue. Anyway, I used your code with some minor changes.
Yes, the jitter happens with the static camera too. But it's not so noticable.
The camera does track the interpolated motionstate, I believe. Doesn't it?

Code: Select all

void Jittering::updateCamera()
{
	...
	//look at the vehicle
	cube->getMotionState()->getWorldTransform(cubeWorldTrans);
	...
}
mi076 wrote:looked at it... Replaced line
cube->applyCentralForce(btVector3(0.0f, btSin(timeGetTime() * 0.001f) * 125.f + 75.f, 0.0f));
with
cube->applyCentralForce(btVector3(0.0f, 100.0f, 0.0f));

and cube is going up smooth like butter..... ??
Yeah, right, that's definetely a solution. :?

Garibalde wrote:...
Thanks, Garibalde.
I have already tried to smooth my timeStep values, but that didn't work. I'll give it a chance again.
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Object jittering (again)

Post by mi076 »

<...>
Last edited by mi076 on Tue Sep 13, 2011 9:14 pm, edited 1 time in total.
User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

Re: Object jittering (again)

Post by dotsquid »

mi076 wrote:definitely not, i didn't say it is a solution... i looked at it on Linux, there is no such function... but it can be smooth... so it is question of stepping and function your use, may be systems with vsync are working your settings better around... just guessing, why on some systems it is better.... surely not going to look into it... so you can save your sarcasm....
Well, I'm sorry. I misunderstood your message.

To all
My further investigation shown that the value of the timeStep I'm passing to stepSimulation fluctuates from 0.016f to 0.017f seconds (I'm using timeGetTime() whose precision is milliseconds) and looks like this:
0:00:01:28.605 0.017
0:00:01:28.622 0.017
0:00:01:28.638 0.016
0:00:01:28.655 0.017
0:00:01:28.671 0.016
0:00:01:28.688 0.017
0:00:01:28.705 0.017
0:00:01:28.721 0.016
0:00:01:28.738 0.017
0:00:01:28.755 0.017
0:00:01:28.771 0.016
0:00:01:28.788 0.017
0:00:01:28.805 0.017
0:00:01:28.821 0.016
0:00:01:28.838 0.017

I simulated the same behaviour in the Jittering sample I've posted above by using the following code:

Code: Select all

	cube->applyCentralForce(btVector3(0.0f, 200.f, 0.0f));

	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

	///step the simulation
	if (m_dynamicsWorld)
	{
		float dt = ((float)rand() / RAND_MAX > 0.5f) ? 0.016f : 0.017f;
		m_dynamicsWorld->stepSimulation(dt);
		...
And voila - jitter is clearly seen. When the velocity is low the jitter is hard to notice, but it becomes more noticeable while the velocity increases.

So now my question is: is it ok or some additional interpolation should be applied? I mean, I could use a more precise timer and smooth its values, but sometimes the performance may suddenly drop for a short period of time, say from 16 ms to 20 ms - and this may cause this ugly jitter. Maybe such behavour isn't often on consoles, but on PC it's quite possible.
Or maybe I do all things completely wrong and my reasoning is wrong too?
Mako_energy02
Posts: 171
Joined: Sun Jan 17, 2010 4:47 am

Re: Object jittering (again)

Post by Mako_energy02 »

This may or may not fix anything, but I couldn't help but notice in that code sample you are leaving the second and third params to StepSimulation() as their defaults. So you are only allowing 1 substep. According to the "Stepping The World" article on the wiki, you need to have the substeps+fixed rate > the first param. If you add a little bit of logic to detect when it goes over the fixed rate, and then adjust the substeps properly, it may help with the jitter. Maybe. >.>
User avatar
Garibalde
Posts: 44
Joined: Fri Dec 18, 2009 6:06 pm
Location: Montreal

Re: Object jittering (again)

Post by Garibalde »

If i recall thats Substeps*InternalTimeStep > Timestep. Yes this maybe a problem if your timestep is a function of frames (i.e Timelapsedbetweenframes() is used)? you will get sudden changes in the Timestep breaking the above relation.
User avatar
dotsquid
Posts: 22
Joined: Fri Jan 14, 2011 7:10 pm
Location: Ukraine

Re: Object jittering (again)

Post by dotsquid »

Hi, thank you for your response.

It's just a mistake of copy-pasting. I've tried increasing the maxSubSteps value, but I get jitter anyway.
The third param fixedTimeStep is default and equal to 1.0 / 60.0 indeed. But I think I shouldn't change it.

Can anybody confirm that jitter exists in the Jittering sample with the following edition?

Code: Select all

   cube->applyCentralForce(btVector3(0.0f, 200.f, 0.0f));

   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 

   ///step the simulation
   if (m_dynamicsWorld)
   {
      float dt = ((float)rand() / RAND_MAX > 0.5f) ? 0.016f : 0.017f;
      m_dynamicsWorld->stepSimulation(dt, 4);
      ...
mi076
Posts: 144
Joined: Fri Aug 01, 2008 6:36 am
Location: Bonn, Germany

Re: Object jittering (again)

Post by mi076 »

ok, no problem, look at this, is it better?
You do not have the required permissions to view the files attached to this post.