I use the Newton engine with Mogre (Ogre wrapper for .NET) and want to use it for collision detection.
For this I create bodies with 2 materialIDs joint by a MaterialPair. With the ContactCallback class I check for its collision / intersection. This generally works fine, but for my case is a problem.
After some experimentations I found out something. It seems so that:
Only when a colliding Body was moved by physics it will be checked for collision.
(Then the debug lines are green instead of red)
If Bodies are only moved by Body.SetPositionOrientation() there is no callback.
I think this is for optimization reason. Is there a way to get a Callback without using (moving by) physics?
e.g. by enable a Newton internal "has moved flag" of a Body? Body.Unfreeze() doesn't work.
Greetings from Germany
Beauty
If it's from interest:
Here is my (simplified) code written with Mogre / C# / MogreNewt:
- Code: Select all
// -- initialization --
MogreNewt.World nWorld = new MogreNewt.World();
MaterialID objectColMaterial = new MaterialID(nWorld);
MaterialID lobeColMaterial = new MaterialID(nWorld);
MaterialPair materialPair = new MaterialPair(nWorld, lobeColMaterial, objectColMaterial);
collisionCallback = new CollisionCallback();
materialPair.SetContactCallback(collisionCallback);
materialPair.SetDefaultCollidable(1);
class CollisionCallback : ContactCallback
{
public CollisionCallback()
{ }
public override int UserBegin()
{
Console.Write(" Collision ? ");
return 1;
}
public override int UserProcess()
{
Console.Write(" Collision !! ");
return 1;
}
}
- Code: Select all
//-- adding 2 types of objects --
MogreNewt.CollisionPrimitives.ConvexHull colHull;
MogreNewt.Body body;
// -- add object type 1 --
colHull = new MogreNewt.CollisionPrimitives.ConvexHull(nWorld, targetNode);
// targetNode is a SceneNode with mesh entity
body = new MogreNewt.Body(nWorld, colHull);
body.SetPositionOrientation(targetNode.WorldPosition,
targetNode.WorldOrientation);
body.MaterialGroupID = objectColMaterial
// body.AttachToNode(targetNode);
// no moving by Newton wanted; move only by SetPositionOrientation()
// -- add object type 2 --
colHull = new MogreNewt.CollisionPrimitives.ConvexHull(
nWorld, vertices, new Quaternion(0, Vector3.UNIT_Y));
body = new MogreNewt.Body(nWorld, colHull);
body.SetPositionOrientation(targetNode.WorldPosition,
targetNode.WorldOrientation);
body.MaterialGroupID = lobeColMaterial
- Code: Select all
// -- calculation --
nWorld.Update(0.001f); // called for each collision check