Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.80 KB | None | 0 0
  1. dynamicsWorld.setInternalTickCallback(new InternalTickCallback() {
  2.                 @Override
  3.                 public void internalTick(DynamicsWorld dynamicsWorld, float timeStep) {
  4.                     try{
  5.                     Dispatcher dispatcher = dynamicsWorld.getDispatcher();
  6.                     int manifoldCount = dispatcher.getNumManifolds();
  7.                     System.out.println(manifoldCount);
  8.                     for (int i = 0; i < manifoldCount; i++) {
  9.                         PersistentManifold manifold = dispatcher.getManifoldByIndexInternal(i);
  10.                         // The following two lines are optional.
  11.                         RigidBody object1 = (RigidBody)manifold.getBody0();
  12.                         RigidBody object2 = (RigidBody)manifold.getBody1();
  13.                         if (object1 != object2){
  14.                         RigidBody physicsObject1 = (RigidBody)object1.getUserPointer();
  15.                         RigidBody physicsObject2 = (RigidBody)object2.getUserPointer();
  16.                         boolean hit = false;
  17.                         javax.vecmath.Vector3f normal = null;
  18.                         for (int j = 0; j < manifold.getNumContacts(); j++) {
  19.                             ManifoldPoint contactPoint = manifold.getContactPoint(j);
  20.                             if (contactPoint.getDistance() < 0.0f) {
  21.                                 hit = true;
  22.                                 normal = contactPoint.normalWorldOnB;
  23.                                 break;
  24.                             }
  25.                         }
  26.                         if (hit) {
  27.                            
  28.                             // Collision happened between physicsObject1 and physicsObject2. Collision normal is in variable 'normal'.
  29.                             System.out.println("Collided!");
  30.                         }
  31.                     }
  32.                     }
  33.                     }catch (Exception e){
  34.                         System.out.println("Much exception. Wow.");
  35.                         e.printStackTrace();
  36.                     }
  37.                 }
  38.             }, null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement