RaycastVehicle on BvhTriangleMeshShape jitter (JBullet)

keely
Posts: 9
Joined: Sat Aug 08, 2009 2:08 am

RaycastVehicle on BvhTriangleMeshShape jitter (JBullet)

Post by keely »

I have RayvastVehicle riding on BvhTriangleMeshShape (256x256 vertices and fixed size polys "heightmaplike")

If I use stepSimulation with maxSubSteps=1 the movement is smooth.
If I use any kind stepSimulation variation, where maxSubSteps > 1, i'm in jitterland.

Any ideas?

I use JBullet (based on Bullet 2.70-beta1) and I'm very sorry if it's not appropriate to ask my question here, but I wasn't able to figure out if the problem is in JBullet or Bullet in general.
keely
Posts: 9
Joined: Sat Aug 08, 2009 2:08 am

Re: RaycastVehicle on BvhTriangleMeshShape jitter (JBullet)

Post by keely »

I realised that somewhere in there, deep in the Jungle of Code, I was reading a value straight from the getWorldTransform and not from the motionstate. It's a amazing what sleep and cup of coffee can do.

Unfortunately, now that I always read from interpolated MotionState, I'm facing a more familiar kind of physicsengine jitter.

The only way to make it run smooth atm is capping frame rate and use non-interpolated data. Maybe use exactly 2 ticks for low fps and one for 60fps+. It's not very robust to cap frame rate in a real-time game so any tips are appreciated.

Since the interpolation data is jittery and raw data is not, I can only assume that something is inaccurate during the interpolation. I don't have enough experience in physics simulation to even begin to speculate where the inaccuracy lies.

I guess the problem is now the same as this poster had/has: http://www.bulletphysics.com/Bullet/php ... cle#p14550

I had no success with making the trimesh polys bigger/smaller like reply suggests. I haven't tried gimpact meshes yet.
sparkprime
Posts: 508
Joined: Fri May 30, 2008 2:51 am
Location: Ossining, New York

Re: RaycastVehicle on BvhTriangleMeshShape jitter (JBullet)

Post by sparkprime »

Interpolation is only for making things appear smooth when visualised -- don't use it in your vehicle physics feedback loops.
keely
Posts: 9
Joined: Sat Aug 08, 2009 2:08 am

Re: RaycastVehicle on BvhTriangleMeshShape jitter (JBullet)

Post by keely »

sparkprime wrote:Interpolation is only for making things appear smooth when visualised -- don't use it in your vehicle physics feedback loops.
Rendering is the only place where I've used (tried to use) interpolated data. It appears jittery compared to non-interpolated data, so atm I'm forced to cap the fps and run simulation with fixed dt per frame. I think this could have something to do with raycastvehicle vs. trimesh in particular, but it's just an educated guess.

Some of my vehicle-settings where kinda "off" earlier (semi-unrealistic values by mistake), and maybe straightening them up smooths the interpolation result, but I haven't tried it yet. However it doesn't make sense to me why these values would not screw up the non-interpolated data at all, and mess up the interpolated stuff.

from Bullet manual:

"Bullet will interpolate the world transform, and send the interpolated worldtransform to the btMotionState, without performing physics simulation."

If I interpret this correctly, the interpolation is only simple transforming, and doesn't include very sophisticated maneuvers, so in my mind it doesn't make sense why would interpolated data be jittery and non-interpolated is not. Either there is a bug/inaccuracy somewhere or I'm using the whole shebang wrong. I would put my money on the latter, but just need some help figuring it out.
keely
Posts: 9
Joined: Sat Aug 08, 2009 2:08 am

Re: RaycastVehicle on BvhTriangleMeshShape jitter (JBullet)

Post by keely »

Still haven't found a solution to this one. I decided to bump the thread with some code samples and youtube-video to illustrate the situation.
I still get jittery movement with vehicle if I'm using interpolated data. Fixing framerate into 1/60 fixes the jitter.

This is how we roll:

Code: Select all

public void gameloop() {
...
        logic();
        render();
...
}

public void render() {
	...
	Transform m = new Transform();
	DefaultMotionState myMotionState = (DefaultMotionState) carPhysix.carChassis.getMotionState();
	m.set(myMotionState.graphicsWorldTrans);
	m.getOpenGLMatrix(mat);	
	GL11.glMultMatrix(FloatBuffer.wrap(mat));
	GL11.glCallList(carRender);	
	...
}

public void updateCarPhysix(float delta) {
...
	wheelIndex = 0;
	vehicle.applyEngineForce(gEngineForce,wheelIndex);
	vehicle.setSteeringValue(gVehicleSteering,wheelIndex);
	vehicle.setBrake(gBreakingForce,wheelIndex);
...
}
The framerate independent -version of the logic()-function which gives us jitters.
Video: http://www.youtube.com/watch?v=kXcCzQoJPqw

Code: Select all

public void logic() {
...
        delta = (float)(clock.getTimeMicroseconds()/1000000f);
        clock.reset();
        physicsEngine.dynamicsWorld.stepSimulation(delta, 10);
        updateCarPhysix(delta);
...
}	
Smooth unindependent version of the logic()-function:
Video: http://www.youtube.com/watch?v=WyWJ5KHrgU8

Code: Select all

public void logic() {
...
        while(clock.getTimeMicroseconds()<1f/60f) { //sleep }
        clock.reset();
        physicsEngine.dynamicsWorld.stepSimulation(1f/60f, 1);
        updateCarPhysix(1f/60f); 
...
}
All the code stays the same in the videos, except given part in logic().

Some questions:
- Am I reading the interpolated motionstate correctly in the render()?
- Should I apply the forces like engineforce to vehicle in some other way/timing (maybe in some callback?) that I currently do in my own function updateCarPhysix()?
- JBullet vehicle demo has this vehicle.updateWheelTransform(i, true); I tried putting this line here and there but it didn't fix my problem. What does this actually do? Update the wheels or update the chassis or both? Should I be calling this and at what point?
- Other tips?
keely
Posts: 9
Joined: Sat Aug 08, 2009 2:08 am

Re: RaycastVehicle on BvhTriangleMeshShape jitter (JBullet)

Post by keely »

I have now implemented interpolation myself and it works fine. I leave it to someone else to figure out what is wrong in with the (J)Bullet implementation. Big thanks to Jezek2 for helping hand @ IRC.