DetectorVolume not firing events

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
Tiba
Posts: 4
Joined: Sun Jan 13, 2013 7:17 am

DetectorVolume not firing events

Post by Tiba » Sat Apr 08, 2017 8:16 am

Hi there, I'm a long time user and have found something that has got me stumped.

I'm making an RTS game and its coming along really well and now I'm up to getting units to fight each other but I'm thinking once its all up and running ill need a way for the units to only crunch numbers for units that are in range.

I have setup a grid of DetectorVolume's and I was hoping to use the events to add and remove units from the grid nodes I have setup but the events are not firing. I know the Volumes are there because I can shoot my mouse ray at them and get some feed back that I have indeed hit a grid node but the events never fire.

My units are setup as CharacterController's and I will be moving the simpler units over to SphereCharacterController at some point later but for now the CharacterController gives me really nice perf(1.2ms) so far with 48 of them all driving around harvesting and building.

My question is what have I don't wrong with the DetectorVolume.

Code: Select all

Public Class PhysicsGridNode
    Inherits DetectorVolume
    Public GridIndex As Index
    Public bounds As BoundingBox


    Public Sub New(shape As BoundingBox, BoxGeometry As Geometry(Of Vector3), _GridIndex As Index, world As AffineTransform)
        MyBase.New(New TriangleMesh(New BEPUphysics.DataStructures.TransformableMeshData(BoxGeometry.VertexList.ToArray, BoxGeometry.IndexList.ToArray, world)))
        bounds = shape
        GridIndex = _GridIndex

        AddHandler EntityBeganTouching, AddressOf BeganTouching
        AddHandler EntityStoppedTouching, AddressOf StoppedTouching
        AddHandler VolumeBeganContainingEntity, AddressOf BeganContaining
        AddHandler VolumeStoppedContainingEntity, AddressOf StoppedContaining

    End Sub
    Private Sub StoppedContaining(volume As DetectorVolume, entity As Entity)

    End Sub

    Private Sub BeganContaining(volume As DetectorVolume, entity As Entity)

    End Sub

    Private Sub StoppedTouching(volume As DetectorVolume, toucher As Entity)

    End Sub

    Private Sub BeganTouching(volume As DetectorVolume, toucher As Entity)

    End Sub

End Class

Norbo
Site Admin
Posts: 4541
Joined: Tue Jul 04, 2006 4:45 am

Re: DetectorVolume not firing events

Post by Norbo » Sat Apr 08, 2017 6:36 pm

A couple of randoguesses:
1) Is the mesh closed? The mesh provided needs to be closed otherwise the containment tests won't work.
2) Is it added to the space?

But I would actually recommend against using a DetectorVolume for this. Instead, you could directly use the broad phase:

Code: Select all

            Space.BroadPhase.QueryAccelerator.GetEntries(boundingSphereOrBox, overlaps);
The broad phase query only collects objects based on the intersection of the bounding boxes, but you can perform more precise tests after that. In most cases, this will be much, much faster than the DetectorVolume which performs detailed triangle-level collision detection.

Tiba
Posts: 4
Joined: Sun Jan 13, 2013 7:17 am

Re: DetectorVolume not firing events

Post by Tiba » Sun Apr 09, 2017 4:17 am

90% sure its closed as I use the same box for rendering and it looks fine, yes its in the space.

I like your your idea for using Space.BroadPhase.QueryAccelerator.GetEntries, is it thread safe or should I just update my grid on the physics thread? I do object avoidance there anyway so building my grid lists shouldn't be an issue, I use the results on the next frame before I tell the physics to update again.

The way I'm thinking it will work is for each frame I clear the node lists after I do what I need with them and then after the physics is done updating call Space.BroadPhase.QueryAccelerator.GetEntries for each grid node and add entries to the node lists and I should have sort of what I'm looking for, I knew there will be some messing around making sure I don't get duplicates but even then a dup wont really matter.

Norbo
Site Admin
Posts: 4541
Joined: Tue Jul 04, 2006 4:45 am

Re: DetectorVolume not firing events

Post by Norbo » Sun Apr 09, 2017 4:05 pm

GetEntries should not be called while the space is potentially updating. It is, however, thread safe to call GetEntries from multiple threads if the space isn't updating.

Tiba
Posts: 4
Joined: Sun Jan 13, 2013 7:17 am

Re: DetectorVolume not firing events

Post by Tiba » Mon Apr 10, 2017 1:44 am

Thanks for the help and the amazing physics lib! BEPU has been rocking my world since 2011!

Norbo
Site Admin
Posts: 4541
Joined: Tue Jul 04, 2006 4:45 am

Re: DetectorVolume not firing events

Post by Norbo » Mon Apr 10, 2017 4:57 pm

:D

Post Reply

Who is online

Users browsing this forum: Baidu [Bot] and 1 guest