Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- dynamicsWorld.setInternalTickCallback(new InternalTickCallback() {
- @Override
- public void internalTick(DynamicsWorld dynamicsWorld, float timeStep) {
- try{
- Dispatcher dispatcher = dynamicsWorld.getDispatcher();
- int manifoldCount = dispatcher.getNumManifolds();
- System.out.println(manifoldCount);
- for (int i = 0; i < manifoldCount; i++) {
- PersistentManifold manifold = dispatcher.getManifoldByIndexInternal(i);
- // The following two lines are optional.
- RigidBody object1 = (RigidBody)manifold.getBody0();
- RigidBody object2 = (RigidBody)manifold.getBody1();
- if (object1 != object2){
- RigidBody physicsObject1 = (RigidBody)object1.getUserPointer();
- RigidBody physicsObject2 = (RigidBody)object2.getUserPointer();
- boolean hit = false;
- javax.vecmath.Vector3f normal = null;
- for (int j = 0; j < manifold.getNumContacts(); j++) {
- ManifoldPoint contactPoint = manifold.getContactPoint(j);
- if (contactPoint.getDistance() < 0.0f) {
- hit = true;
- normal = contactPoint.normalWorldOnB;
- break;
- }
- }
- if (hit) {
- // Collision happened between physicsObject1 and physicsObject2. Collision normal is in variable 'normal'.
- System.out.println("Collided!");
- }
- }
- }
- }catch (Exception e){
- System.out.println("Much exception. Wow.");
- e.printStackTrace();
- }
- }
- }, null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement