Hi guys,
I'm trying to implement a work with Box2D. And in order to implement collision detection, as far as i could search on web, I have to create a class that extends ContactListener.
The problem is that Processing is complaining that ContactListener must be a class. And after exploring the Box2D's docs, I saw that ContactListener is, in fact, a 'interface' not a class.
Ok... that explains why Processign was complaining. But... do not solve my problem...
Well, I'm not a Java guru, but I tried do do some thing:
Code:
class MyCollisions implements ContactListener{
ArrayList contacts;
MyCollisions(){
}
void persist(ContactPoint point){
println("Persist Contact");
}
void Add(ContactPoint point){
println("COLLISION ----------------------------------");
println("shape1: "+point.shape1);
println("shape2: "+point.shape2);
println("separation: "+point.separation);
println("position: "+point.position);
}
void remove(ContactPoint point){
println("Remove Contact");
}
void result(ContactPoint point){
println("Result Contact");
}
}
Ok... now Processing seems to be ok with the 'implements' task.
But now... a new problem!
Processing complains:
Code:The type box_00.Colisoes must implement the inherited abstract method ContactListener.persist(ContactPoint)
now... i am stuck! As you can see... I do implement all the methods from ContactListener interface. Unless there is some secret way to implement sucha methods, diferent from what i did.
Does anyone knows how can I implement a java interface?
thanks in advance,
Paulo
P.S.: down here is the ContactListener code:
Code:
/*
* JBox2D - A Java Port of Erin Catto's Box2D
[...] */
package org.jbox2d.dynamics;
import org.jbox2d.dynamics.contacts.ContactPoint;
import org.jbox2d.dynamics.contacts.ContactResult;
public interface ContactListener {
/**
* Called when a contact point is added. This includes the geometry
* and the forces.
*/
public void add(ContactPoint point);
/**
* Called when a contact point persists. This includes the geometry
* and the forces.
*/
public void persist(ContactPoint point);
/**
* Called when a contact point is removed. This includes the last
* computed geometry and forces.
*/
public void remove(ContactPoint point);
public void result(ContactResult point);
}