Buffering Linear Velocity.

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

Buffering Linear Velocity.

Post by Peter Prins »

It seems that there is no way to get a buffered version of an Entities Linear Velocity. When running the engine with internal time stepping, How safe is it to get the entity's LinearVelocity directly, and how well does this work?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Buffering Linear Velocity.

Post by Norbo »

Buffered linear velocity does exist, but not interpolated linear velocity. Only position and orientation is interpolated as smoothly changing velocities are not typically important for graphics.

The buffered states can be found in entity.BufferedStates.States property. They are also accessible from the space's buffered states manager.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Buffering Linear Velocity.

Post by Norbo »

Also, if you're just using internal time stepping without asynchronous updating, using the direct entity velocity properties is perfectly safe. The buffered states need only be used when asynchronous access is an issue.
Peter Prins
Posts: 54
Joined: Fri Mar 11, 2011 11:44 pm

Re: Buffering Linear Velocity.

Post by Peter Prins »

So if I have this piece of code:

Code: Select all

if (Environment.ProcessorCount > 1)
{
    for (int i = 0; i < Environment.ProcessorCount; i++)
        space.ThreadManager.AddThread();
}
I do need to use the buffered states?
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: Buffering Linear Velocity.

Post by Norbo »

No; that tells the engine to use multiple threads internally to speed up processing. That is not the same as updating asynchronously.

Using internal multithreading is mostly transparent to external systems, with a few exceptions (other asynchronous systems should be designed knowing the engine will use up however many threads it has, 'immediate' collision events will be called from the context of an internal thread and so some operations are unsafe).

Asynchronous updating is when the physics engine is free-running on a separate thread. In this case, it's not safe to access the physics data from the main thread for example, so you would need to go through the buffers. More information can be found here: http://bepuphysics.codeplex.com/wikipag ... umentation

(Asynchronous updating and internal multithreading are not mutually exclusive, either; you can have physics updating on one thread with multiple threads added to the thread manager. Doing this sort of stuff requires careful consideration of load balancing, though.)
Post Reply