I continue to work with Phys2D

For exclusion, i use bitmask :
1 2 3 4
| public static final long MASK_NONE = 0; public static final long MASK_ROAD_CAR = 1; public static final long MASK_CAR_CAR = 2; public static final long MASK_OPTION_CAR = 4; |
For "road" body, i use MASK_ROAD_CAR.
For "car" body, i use MASK_ROAD_CAR | MASK_CAR_CAR | MASK_OPTION_CAR
...
It work fine. But i came accros another problem

1 2 3 4 5 6 7 8 9 10 11 12 13
| for(int i=0;i<NB_V;i++) { cars[i].step(); } world.step(); for(int i=0;i<NB_V;i++) { int val = map.crossStart(cars[i]); if (val != 0) { System.out.println("Start : "+val); } } |
In Map.crossStart, I test if a car cross the start line.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| public int crossStart(Car car) { float cx1 = car.getPosition().getX(); float cy1 = car.getPosition().getY(); float cx2 = car.getLastPosition().getX(); float cy2 = car.getLastPosition().getY(); Line l = (Line)start.getShape(); float sx1 = l.getX1(); float sy1 = l.getY1(); float sx2 = l.getX2(); float sy2 = l.getY2(); float nx = (sx2-sx1); float ny = (sy2-sy1); int signe1 = (int)Math.signum((cx1-sx1)*(ny)-(cy1-sy1)*(nx)); int signe2 = (int)Math.signum((cx2-sx1)*(ny)-(cy2-sy1)*(nx)); if (signe1 == signe2) { return 0; } float ln = (float)(Math.sqrt(nx*nx+ny*ny)); nx = nx/ln; ny = ny/ln;
float dist = (cx1-sx1)*nx+(cy1-sy1)*ny; if ((dist<0)||(dist>ln)) { return 0; } return signe1; } |
If i use the Body.getLastPosition to do the test, it didn't work.
1 2 3 4 5 6 7 8 9 10 11 12
| class Car { [...] public ROVector2f getPosition() { return body.getPosition(); } public ROVector2f getLastPosition() { return body.getLastPosition(); } |
If i store the current possition before World.step(), it work.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| class Car { [...] public ROVector2f getPosition() { return body.getPosition(); } public void step() { lastPosition.set(body.getPosition().getX(),body.getPosition().getY()); } public ROVector2f getLastPosition() { return lastPosition; } } |
Body.getLastPosition didn't mean to return the position of the body before the world.step() ?