[V2] Any sample for forcefield?

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
b1fg2
Posts: 19
Joined: Mon Sep 24, 2018 3:36 pm

[V2] Any sample for forcefield?

Post by b1fg2 »

is there any sample for forcefield simulation? E.g a forcefield volume will affect any object that inside the volume.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [V2] Any sample for forcefield?

Post by Norbo »

Not at the moment, but querying the broad phase for bodies with overlapping bounding boxes is a good start. Something like:

Code: Select all

            var broadPhaseEnumerator = new BroadPhaseOverlapEnumerator { Pool = BufferPool, References = new QuickList<CollidableReference>(16, BufferPool) };
            Simulation.BroadPhase.GetOverlaps(queryBoundsMin, queryBoundsMax, ref broadPhaseEnumerator);
where the BroadPhaseOverlapEnumerator is:

Code: Select all

        struct BroadPhaseOverlapEnumerator : IBreakableForEach<CollidableReference>
        {
            public QuickList<CollidableReference> References;
            //The enumerator never gets stored into unmanaged memory, so it's safe to include a reference type instance.
            public BufferPool Pool;
            public bool LoopBody(CollidableReference reference)
            {
                References.Allocate(Pool) = reference;
                //If you wanted to do any top-level filtering, this would be a good spot for it.
                //The CollidableReference tells you whether it's a body or a static object and the associated handle. You can look up metadata with that.
                return true;
            }
        }
You could then walk over the overlaps and modify the velocity of any detected bodies.

The collision query demo shows how to detect bodies with contact-level precision. It's more complicated since it involves the CollisionBatcher.
Post Reply