Problem with Compound Bodies intersection events
Posted: Thu Nov 21, 2013 4:26 pm
Hello,
if got a Problem by the interesection checking of compound bodies.....
If I specify Tags in coumpound body and in Ini like this:
ini.CollisionInformation.Tag = “ini_1”;
compoundBody.CollisionInformation.Tag = “compound_payload”;
and if I register event handling to ini like like we correctly do (i hope so):
ini.CollisionInformation.Events.EndOfCollision += Event_EndOfCollision; // or start
I get both A and B collidables correctly, but TAG of compound collidable is NULL, even if I set it correctly before.
Tag of ini collidable is OK.
I tried to solve it thousand ways, I tried even compound body demo in bepu. And still the same result. But:
Here here is an interesting thing – when I register collision event handler not to INI, but to Compound body thing, like:
compoundBody.CollisionInformation.Events.EndOfCollision += Event_EndOfCollision;
then on collision event I get correctly both of Tags…. And strings from them!
Here the CompundBodieDemo changed to Show the Problem....
if got a Problem by the interesection checking of compound bodies.....
If I specify Tags in coumpound body and in Ini like this:
ini.CollisionInformation.Tag = “ini_1”;
compoundBody.CollisionInformation.Tag = “compound_payload”;
and if I register event handling to ini like like we correctly do (i hope so):
ini.CollisionInformation.Events.EndOfCollision += Event_EndOfCollision; // or start
I get both A and B collidables correctly, but TAG of compound collidable is NULL, even if I set it correctly before.
Tag of ini collidable is OK.
I tried to solve it thousand ways, I tried even compound body demo in bepu. And still the same result. But:
Here here is an interesting thing – when I register collision event handler not to INI, but to Compound body thing, like:
compoundBody.CollisionInformation.Events.EndOfCollision += Event_EndOfCollision;
then on collision event I get correctly both of Tags…. And strings from them!
Here the CompundBodieDemo changed to Show the Problem....
Code: Select all
using BEPUphysics.Entities.Prefabs;
using BEPUphysics.CollisionShapes;
using BEPUphysics.CollisionShapes.ConvexShapes;
using System.Collections.Generic;
using System.Diagnostics;
using BEPUutilities;
namespace BEPUphysicsDemos.Demos
{
/// <summary>
/// Compound bodies are created from other entities to make concave shapes.
/// </summary>
public class CompoundBodiesDemo : StandardDemo
{
/// <summary>
/// Constructs a new demo.
/// </summary>
/// <param name="game">Game owning this demo.</param>
public CompoundBodiesDemo(DemosGame game)
: base(game)
{
//Build the first body
var bodies = new List<CompoundShapeEntry>
{
new CompoundShapeEntry(new SphereShape(.5f), new Vector3(0, 1, 0), 1),
new CompoundShapeEntry(new ConeShape(2, .5f), new Vector3(1, 1, 0), 1),
new CompoundShapeEntry(new SphereShape(.5f), new Vector3(-1, 1, 0), 1)
};
var cb1 = new CompoundBody(bodies, 45);
//Build the second body
bodies = new List<CompoundShapeEntry>
{
new CompoundShapeEntry(new BoxShape(1,1,1), new Vector3(0, 3, 0), 1),
new CompoundShapeEntry(new BoxShape(1,1,1), new Vector3(1, 3.5f, 0), 1),
};
var cb2 = new CompoundBody(bodies, 4);
bodies = new List<CompoundShapeEntry>();
//Build the third Braum's-fry style body
for (int k = 0; k < 7; k++)
{
bodies.Add(new CompoundShapeEntry(new BoxShape(1, 1, 1), new Vector3(-4 + k * .7f, 2 + .7f * k, 2 + k * .2f), 1));
}
var cb3 = new CompoundBody(bodies, 7);
//Add them all to the space
cb3.CollisionInformation.Tag = "cb";
Space.Add(cb3);
// Space.Add(cb2);
// Space.Add(cb1);
Box ground = new Box(new Vector3(0, -.5f, 0), 10, 1, 10);
ground.CollisionInformation.Tag = "ground";
ground.CollisionInformation.Events.InitialCollisionDetected += Events_InitialCollisionDetected;
// cb3.CollisionInformation.Events.InitialCollisionDetected += Events_InitialCollisionDetected;
Space.Add(ground);
game.Camera.Position = new Vector3(0, 3, 15);
}
void Events_InitialCollisionDetected(BEPUphysics.BroadPhaseEntries.MobileCollidables.EntityCollidable sender, BEPUphysics.BroadPhaseEntries.Collidable other, BEPUphysics.NarrowPhaseSystems.Pairs.CollidablePairHandler pair)
{
string a = ((string)pair.CollidableA.Tag);
string b = ((string)pair.CollidableB.Tag);
}
/// <summary>
/// Gets the name of the simulation.
/// </summary>
public override string Name
{
get { return "Compound Bodies"; }
}
}
}