final Box box2 = new Box(1,1,1);
box2.setEnvelope(1);
// attach geometries to bodies (to we can change the transform of the
// boxes by changing the transform of the bodies)
final Body body1 = new Body("box1", box1);
final Body body2 = new Body("box2", box2);
// contact generator
ContactGenerator g = new SupportMapContactGenerator(box1,box1,box2,box2);
/*
* Test 1, displace along positive y-axis
*/
// displace box2
body2.setPosition(0, 1.5, 0);
// run contact point generation
g.run();
// extract contact points
result.clear();
Iterator<ContactPoint> i = g.getContacts();
while (i.hasNext()) {
ContactPoint cp = i.next();
System.out.println(cp.point);
System.out.println("dist="+cp.distance);
result.add(new Vector3(cp.point));
}
// expected contact points, in counter clock-wise order
expect.clear();
expect.add(new Vector3(0.5,0.75,0.5));
expect.add(new Vector3(-0.5,0.75,0.5));
expect.add(new Vector3(-0.5,0.75,-0.5));
expect.add(new Vector3(0.5,0.75,-0.5));
// check
assertTrue(verifyPolygon(expect, result));
/*
* Test 2, displace along negative y-axis
*/
// displace box2
body2.setPosition(0, -1.5, 0);
// run contact point generation
g.run();
// extract contact points
result.clear();
i = g.getContacts();
while (i.hasNext()) {
ContactPoint cp = i.next();
System.out.println(cp.point);
System.out.println("dist="+cp.distance);
result.add(new Vector3(cp.point));
}
// expected contact points, in counter clock-wise order
expect.clear();
expect.add(new Vector3( 0.5,-0.75,-0.5));
expect.add(new Vector3(-0.5,-0.75,-0.5));
expect.add(new Vector3(-0.5,-0.75, 0.5));
expect.add(new Vector3( 0.5,-0.75, 0.5));
// check
assertTrue(verifyPolygon(expect, result));
/*
* Test 3, displace along positive x-axis
*/
// displace box2
body2.setPosition(1.5, 0, 0);
// run contact point generation
g.run();
// extract contact points