[Raycast] How to use the filter function

Discuss any questions about BEPUphysics or problems encountered.
Post Reply
thiago
Posts: 22
Joined: Sat Oct 16, 2010 10:32 pm

[Raycast] How to use the filter function

Post by thiago »

iam using this version of the raycast

space.RayCast(raio, maxDistance, Filter, results)

the filter is a function like this

private bool Filter(BroadPhaseEntry entry)
{
...
}

supose i want the raycast to work only with Static meshes, i should use this filter ? how can i know what the BroadPhaseEntry is ? lots of "IS A" in the code? this will run for each objecct "near" the ray, would be slow ?

---
PloobsEngine Released: http://ploobs.com.br/?p=504
Last edited by thiago on Sat Apr 02, 2011 6:04 pm, edited 2 times in total.
thiago
Posts: 22
Joined: Sat Oct 16, 2010 10:32 pm

Re: [Raycast] How to use the filter function

Post by thiago »

More questions.
in the last version i used:
space.BroadPhase.GetEntities(new BoundingSphere(po.Position,distance),ent);
to get the entities inside a bounding sphere, how can i do this now ?
[edit] space.BroadPhase.QueryAccelerator ? i found ...

--
and to detect the colisions happening with an entity
Entity.CollisionPairs and iterate throw it
how now ?
iam using
foreach (var item in bo.Entity.CollisionInformation.OverlappedCollidables)
to recover the entities and the triangles meshes i need to
check if the collidable is EntityCollidable and if it is i recover the entity ? Also check if it is a StaticMesh ....
too many casts, iam afraid >.<
BroadphaseEntry can be a Collidable
Collidable can be Static Mesh and EntityCollidable (in my case now)
EntityCollidable has an entity
the entity has the tag (where i put my game object)
look at my code

Code: Select all

internal static IPhysicObject RecoverFromBroadPhaseEntry(BroadPhaseEntry entry)
        {
            IPhysicObject phyObj = null;
            if (entry is Collidable)
            {         
                Collidable collidable = (entry as Collidable);
                if (collidable is EntityCollidable)
                {
                    phyObj = (collidable as EntityCollidable).Entity.Tag as IPhysicObject;
                }
                if (collidable is StaticMesh)
                {
                    phyObj = (collidable as StaticMesh).Tag as IPhysicObject;
                }             
            }
            return phyObj;
        }
is there another way ?

--
I cant put scale in the entity.WorldTransform matrix
and in the static mesh constructor ? can i ?
triangleGroup = new StaticMesh(vertices, indices, new AffineTransform(scale, Quaternion.CreateFromRotationMatrix(rotation), position));
it works ? or i need to apply the scale by hand (multiplying all vertices) ?

thanks as always

---
PloobsEngine Released: http://ploobs.com.br/?p=504
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [Raycast] How to use the filter function

Post by Norbo »

supose i want the raycast to work only with Static meshes, i should use this filter ? how can i know what the BroadPhaseEntry is ? lots of "IS A" in the code? this will run for each objecct "near" the ray, would be slow ?
Using "is" or an "as" followed by a null check would suffice. I wouldn't worry about performance too much. The type checking will take a matter of dozens of nanoseconds. Unless there are many, many thousands of such queries per frame, it will be unnoticeable.
to get the entities inside a bounding sphere, how can i do this now ?
[edit] space.BroadPhase.QueryAccelerator ? i found ...
Yup!
check if the collidable is EntityCollidable and if it is i recover the entity ? Also check if it is a StaticMesh ....
While I wouldn't worry about performance here either (unless it's happening every frame on every object), I do agree that it's pretty annoying to do that amount of casting to grab a tag.

How about adding a Tag to the BroadPhaseEntry itself? It appears that that would avoid the casting issues entirely.
I cant put scale in the entity.WorldTransform matrix
Correct; that property is designed to only accept rigid transformations, since an entity's state is defined using rigid transforms (orientation and position). If you need to transform a convex shape using any arbitrary linear transform, consider using the TransformableShape (or TransformableEntity for convenience).
and in the static mesh constructor ? can i ?
triangleGroup = new StaticMesh(vertices, indices, new AffineTransform(scale, Quaternion.CreateFromRotationMatrix(rotation), position));
it works ? or i need to apply the scale by hand (multiplying all vertices) ?
That should work fine. Applying it by hand would work as well, or multiplying multiple transformation matrices to construct the AffineTransform. StaticMeshes are designed to use AffineTransforms, unlike Entities. AffineTransforms are a superset of RigidTransforms. In addition to the rigid transform's orientation and position, affine transforms offer uniform or non-uniform scaling and shearing.
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [Raycast] How to use the filter function

Post by Norbo »

I went ahead and pushed a new version to the development fork which includes a tag on all BroadPhaseEntries, you can grab it here: http://bepuphysics.codeplex.com/SourceC ... evelopment
thiago
Posts: 22
Joined: Sat Oct 16, 2010 10:32 pm

Re: [Raycast] How to use the filter function

Post by thiago »

Thanks again.
--
PloobsEngine released
http://ploobsengine.codeplex.com/
thiago
Posts: 22
Joined: Sat Oct 16, 2010 10:32 pm

Re: [Raycast] How to use the filter function

Post by thiago »

iam getting some compile error trying to compile this version you posted
in MeshingBoundingBoxTree.cs
Error 1 The namespace 'BEPUphysics.DataStructures' already contains a definition for 'MeshBoundingBoxTree' C:\Users\tpastor\Desktop\bepuCode\BEPUphysics\DataStructures\Deprecated\MeshBoundingBoxTree.cs 23 18 BEPUphysics

Error 2 The type 'BEPUphysics.DataStructures.MeshBoundingBoxTree' already contains a definition for 'Node' C:\Users\tpastor\Desktop\bepuCode\BEPUphysics\DataStructures\Deprecated\MeshBoundingBoxTree.cs 724 25 BEPUphysics

i just cloned the repo, unloaded the w7 and xbox projects and compiled.

--
PloobsEngine released
http://ploobsengine.codeplex.com/
Norbo
Site Admin
Posts: 4929
Joined: Tue Jul 04, 2006 4:45 am

Re: [Raycast] How to use the filter function

Post by Norbo »

Yeah sorry about that, after fixing the WP7/Xbox360 versions I forgot that I had enabled compilation on the Windows versions for testing :)

To fix it, just right click on the DataStructures/Deprecated trees and set their build action to none.
thiago
Posts: 22
Joined: Sat Oct 16, 2010 10:32 pm

Re: [Raycast] How to use the filter function

Post by thiago »

Thanks, worked like a charm
--
PloobsEngine released
http://ploobsengine.codeplex.com/
Post Reply