Problem with LinearVelocity and no movement

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
skyflashde
Posts: 5
Joined: Mon Apr 28, 2014 8:29 am

Problem with LinearVelocity and no movement

Post by skyflashde »

Ok, after that bug was fixed yesterday I was able to do most of what I wanted. I am converting pos and rot now and the "aircraft" camera is moving at the right speeds most of the time and almost into the right direction (I still have an unexplained difference of like 1 degree versus the correct movement - I am still thinking about why that happens, but its probably the LatLonAlt to Meter conversion process).

But now that I have fixed most coordinate system problems I still have a problem with LinearVelocity and objects that stop moving slowly despite having LinarVelocity.

This is from the debugger:

obj.PhysicsEntity.LinearVelocity {2.107735, -0.01689263, -1.474374} BEPUutilities.Vector3

and this is never changing:

obj.PhysicsEntity.Position {-4013779, 49.87001, -5923159} BEPUutilities.Vector3

It does not always happen, I have seen objects move slow, but this object now is not moving for reasons I do not understand yet. Is it something like a rounding problem? The speed is too slow? Or what could be the problem?
I have also looked at the BufferedStates, but nothing is moving there either.

I am not doing much in my code with BEPU, so I have not really changed any defaults. This is like my complete BEPU code:

Code: Select all

public Space PhysicsSpace = new Space();

Data.PhysicsSpace.BufferedStates.Enabled = true;
Data.PhysicsSpace.TimeStepSettings.MaximumTimeStepsPerFrame = 10;
Data.PhysicsSpace.TimeStepSettings.TimeStepDuration = ((float)CALCULATE_POSITIONS_TIME_INTERVAL_MS) / 1000 / 10;

Data.PhysicsSpace.Update((float)(ms / 1000));

obj.PhysicsEntity = new BEPUphysics.Entities.Prefabs.Box(new BEPUutilities.Vector3(), 14, 6, 16);
obj.PhysicsEntity.Mass = 0.000001f;
PhysicsSpace.Add(obj.PhysicsEntity);
Am I doing something wrong? I have converted LatLonAlt to meters, do I need to scale it differently?

Thx for all the help!
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Problem with LinearVelocity and no movement

Post by Norbo »

obj.PhysicsEntity.LinearVelocity {2.107735, -0.01689263, -1.474374} BEPUutilities.Vector3

and this is never changing:

obj.PhysicsEntity.Position {-4013779, 49.87001, -5923159} BEPUutilities.Vector3
32 bit floating point numbers in C# have 24 bits in the significand. That significand is then scaled to represent other values in a wide range. For example, 32 bit floats can represent every integer value from -16777216 to 16777216, but not every integer beyond that.

In this example, -4013779 is being added to 2.107735 * dt. If dt is something like 1/60, then the per frame displacement is around 0.04. 4013778.96 would demand ~29 bits of precision, so it gets rounded out.

To support enormous areas with fine precision, there are few common strategies:
1) Recenter the simulation so the origin is relatively close. Keeping simulated objects within 10,000 units of the origin would provide ~0.001 unit precision. That tends to be enough for most physical purposes.
2) For large worlds which require constant simulation everywhere, the simulation can be split into a bunch of different chunks such that no object is more than some distance away from the local simulation origin. (I know at least one big-world-MMO-type game using this approach with BEPUphysics.)
3) Swap all the 32 bit floats for 64 bit doubles. A few people have done this successfully. There's a fork with it, though it hasn't been updated in a while: http://bepuphysics.codeplex.com/SourceC ... leEnhanced

Of the options, I would recommend #1 if it is applicable. It's easier to stay updated as changes are made to the engine than with #3.

Code: Select all

obj.PhysicsEntity.Mass = 0.000001f;
Watch out: this value might cause some trouble if there are any interactions with other dynamic objects, both because of the numerical issues above and the default tuning of the engine.
skyflashde
Posts: 5
Joined: Mon Apr 28, 2014 8:29 am

Re: Problem with LinearVelocity and no movement

Post by skyflashde »

Ok thx, that's about what I thought.
I was just wondering because scaling down didn't immediately solve my problem. Probably did something else wrong.

I replaced the mass already with something bigger. :)
Post Reply