Just tried to use the contact pair concept for colliding several objects and does not seem quite sound: Do I have to register the contact pair for 100 objects that can collide with each other for each possible pair?! This would mean to register it 4950 times (100!/(98!*2!)) 8-O
Addionally when I do
world.addContactPair( a, b, pair1 )
world.addContactPair( b, c, pair2 )
world.addContactPair( a, c, pair2 )
pair1 is not regarded any more!
Have I misunderstood something very badly? Or is the ContactPair solution simply impractical?
I have written a unit test to check the behaviour described above:
package jmextest.physics;
import junit.framework.TestCase;
import com.jme.scene.Node;
import com.jmex.physics.*;
import com.jmex.physics.contact.ContactPair;
import com.jmex.physics.types.PhysicsSphere;
import org.odejava.collision.Contact;
/**
* @author irrisor
* @created 09.04.2005, 13:16:49
*/
public class ContactTest extends TestCase
{
public void testContactPairAssignment()
{
PhysicsWorld.create();
final Node sphere1Node = new Node("sphere1");
final DynamicPhysicsObject sphere1 = new DynamicPhysicsObject( sphere1Node, new PhysicsSphere( 1 ), 1 );
final PhysicsWorld physicsWorld = PhysicsWorld.getInstance();
physicsWorld.addObject( sphere1 );
final Node sphere2Node = new Node("sphere2");
final DynamicPhysicsObject sphere2 = new DynamicPhysicsObject( sphere2Node, new PhysicsSphere( 1 ), 1 );
physicsWorld.addObject( sphere2 );
final Node sphere3Node = new Node("sphere3");
final DynamicPhysicsObject sphere3 = new DynamicPhysicsObject( sphere3Node, new PhysicsSphere( 1 ), 1 );
physicsWorld.addObject( sphere3 );
final boolean[] pairsAsked = new boolean[3];
final ContactPair contactPair_1_2 = new ContactPair()
{
public void onContact( PhysicsObject object1, PhysicsObject obj2, Contact contact )
{
System.out.println( "1 & 2 processed" );
pairsAsked[0] = true;
}
};
physicsWorld.addContactPair( sphere1, sphere2, contactPair_1_2 );
final ContactPair contactPair_1_3 = new ContactPair()
{
public void onContact( PhysicsObject object1, PhysicsObject obj2, Contact contact )
{
System.out.println( "1 & 3 processed" );
pairsAsked[1] = true;
}
};
physicsWorld.addContactPair( sphere1, sphere3, contactPair_1_3 );
final ContactPair contactPair_2_3 = new ContactPair()
{
public void onContact( PhysicsObject object1, PhysicsObject obj2, Contact contact )
{
System.out.println( "2 & 3 processed" );
pairsAsked[2] = true;
}
};
physicsWorld.addContactPair( sphere2, sphere3, contactPair_2_3 );
physicsWorld.update( 1 );
assertTrue( "1 & 2 collision not processed correctly", pairsAsked[0] );
assertTrue( "1 & 3 collision not processed correctly", pairsAsked[1] );
assertTrue( "2 & 3 collision not processed correctly", pairsAsked[2] );
}
}
But it seems to me that it's not very useful to repair the contact pair any more...