Author Topic: Some questions about CollisionEvent  (Read 1059 times)

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Some questions about CollisionEvent
« on: November 07, 2013, 05:48:43 am »
Code: [Select]
CollisionEvent event;
int[] ids = event.getPolygonIDs();
Object3D[] objs = event.getTargets();

When objs.length > 1, how to judge which PolygonID(ids[j]) belongs to which Object3D(objs[j])? For example, to calc:

Code: [Select]
SimpleVector normal = objs[i].getPolygonManager().getTransformedNormal(ids[i]);
« Last Edit: November 07, 2013, 06:25:21 am by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Some questions about CollisionEvent
« Reply #1 on: November 07, 2013, 10:48:40 am »
The getTargets()-methods was a late addition for some purpose that i don't know anymore. Maybe somebody requested that. It has not direct relation to the getPolygonIds()-method. That method returned the affected polygons for the object that actually received this event if it's of type target. What this means is, that if you assign a listener to some object and that object is the target of a collision, then you'll get the polygon ids for that object in the ids-array. If you want that for multiple targets, you have to assign the listener to multiple objects.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Some questions about CollisionEvent
« Reply #2 on: November 07, 2013, 12:31:34 pm »
Code: [Select]
class MyListener implements CollisionListener{

  @Override
  public void collision(CollisionEvent event) {
    int[] ids = event.getPolygonIDs();
    Object3D[] objs = event.getTargets();
  }

  @Override
  public boolean requiresPolygonIDs() {
    // TODO Auto-generated method stub
    return true;
  }
}

//Assume a car collide with 2 walls;
public void test(){

     MyListener listener = new MyListener();
   
    Object3D wall_1;
    wall_1.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
   
    Object3D wall_2;
    wall_2.setCollisionMode(Object3D.COLLISION_CHECK_OTHERS);
   
    Object3D car;
    car.setCollisionMode(Object3D.COLLISION_CHECK_SELF);
   
    wall_1.addCollisionListener(listener);
    wall_2.addCollisionListener(listener);
    car.checkForCollisionEllipsoid(translation, ellipsoid, recursionDepth);
  }
 
When the car collides with both of wall_1 and wall_2 at the same time, the objs = event.getTargets() will contain wall_1 and wall_2, and the ids = event.getPolygonIDs() will contain some polygonIDs of wall_1 and some polygonIDs of wall_2, right?

If that's correct, how could i judge which polygonIDs belongs to wall_1?(and which belongs to wall_2)

Or should i assign 2 different listeners to 2 walls?
« Last Edit: November 07, 2013, 12:34:02 pm by kiffa »

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 11777
    • View Profile
    • http://www.jpct.net
Re: Some questions about CollisionEvent
« Reply #3 on: November 07, 2013, 08:42:57 pm »
When the car collides with both of wall_1 and wall_2 at the same time, the objs = event.getTargets() will contain wall_1 and wall_2, and the ids = event.getPolygonIDs() will contain some polygonIDs of wall_1 and some polygonIDs of wall_2, right?
No, wrong. That's what i tried to say with
Quote
It has not direct relation to the getPolygonIds()-method.
You have to attach the listener to both walls and you'll get the corresponding ids from both listener calls. The getTargets()-method was a late addition to the listener interface that somebody requested. Even if the event is of type source, you'll get all targets by calling that method but not a single polygon id.

Offline kiffa

  • long
  • ***
  • Posts: 199
    • View Profile
Re: Some questions about CollisionEvent
« Reply #4 on: November 08, 2013, 09:01:03 am »
I'm clear, Thanks!