Merge pull request #445 from Fadorico/master

Fixed collision group listeners not being notified
cleanup_build_scripts
Kirill Vainer 9 years ago
commit b4d295ee1b
  1. 2
      jme3-bullet-native/src/native/cpp/jmeClasses.cpp
  2. 1
      jme3-bullet-native/src/native/cpp/jmeClasses.h
  3. 24
      jme3-bullet-native/src/native/cpp/jmePhysicsSpace.cpp
  4. 15
      jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java
  5. 8
      jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java

@ -40,6 +40,7 @@ jclass jmeClasses::PhysicsSpace;
jmethodID jmeClasses::PhysicsSpace_preTick;
jmethodID jmeClasses::PhysicsSpace_postTick;
jmethodID jmeClasses::PhysicsSpace_addCollisionEvent;
jmethodID jmeClasses::PhysicsSpace_notifyCollisionGroupListeners;
jclass jmeClasses::PhysicsGhostObject;
jmethodID jmeClasses::PhysicsGhostObject_addOverlappingObject;
@ -137,6 +138,7 @@ void jmeClasses::initJavaClasses(JNIEnv* env) {
PhysicsSpace_preTick = env->GetMethodID(PhysicsSpace, "preTick_native", "(F)V");
PhysicsSpace_postTick = env->GetMethodID(PhysicsSpace, "postTick_native", "(F)V");
PhysicsSpace_addCollisionEvent = env->GetMethodID(PhysicsSpace, "addCollisionEvent_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;Lcom/jme3/bullet/collision/PhysicsCollisionObject;J)V");
PhysicsSpace_notifyCollisionGroupListeners = env->GetMethodID(PhysicsSpace, "notifyCollisionGroupListeners_native","(Lcom/jme3/bullet/collision/PhysicsCollisionObject;Lcom/jme3/bullet/collision/PhysicsCollisionObject;)Z");
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return;

@ -46,6 +46,7 @@ public:
static jmethodID PhysicsSpace_addCollisionEvent;
static jclass PhysicsGhostObject;
static jmethodID PhysicsGhostObject_addOverlappingObject;
static jmethodID PhysicsSpace_notifyCollisionGroupListeners;
static jclass Vector3f;
static jmethodID Vector3f_set;

@ -187,8 +187,28 @@ void jmePhysicsSpace::createPhysicsSpace(jfloat minX, jfloat minY, jfloat minZ,
jmeUserPointer *up0 = (jmeUserPointer*) co0 -> getUserPointer();
jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer();
if (up0 != NULL && up1 != NULL) {
collides = (up0->group & up1->groups) != 0;
collides = collides && (up1->group & up0->groups);
collides = (up0->group & up1->groups) != 0 || (up1->group & up0->groups) != 0;
if(collides){
jmePhysicsSpace *dynamicsWorld = (jmePhysicsSpace *)up0->space;
JNIEnv* env = dynamicsWorld->getEnv();
jobject javaPhysicsSpace = env->NewLocalRef(dynamicsWorld->getJavaPhysicsSpace());
jobject javaCollisionObject0 = env->NewLocalRef(up0->javaCollisionObject);
jobject javaCollisionObject1 = env->NewLocalRef(up1->javaCollisionObject);
jboolean notifyResult = env->CallBooleanMethod(javaPhysicsSpace, jmeClasses::PhysicsSpace_notifyCollisionGroupListeners, javaCollisionObject0, javaCollisionObject1);
env->DeleteLocalRef(javaPhysicsSpace);
env->DeleteLocalRef(javaCollisionObject0);
env->DeleteLocalRef(javaCollisionObject1);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return collides;
}
collides = (bool) notifyResult;
}
//add some additional logic here that modified 'collides'
return collides;

@ -336,6 +336,21 @@ public class PhysicsSpace {
collisionEvents.add(eventFactory.getEvent(PhysicsCollisionEvent.TYPE_PROCESSED, node, node1, manifoldPointObjectId));
}
private boolean notifyCollisionGroupListeners_native(PhysicsCollisionObject node, PhysicsCollisionObject node1){
PhysicsCollisionGroupListener listener = collisionGroupListeners.get(node.getCollisionGroup());
PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(node1.getCollisionGroup());
boolean result = true;
if(listener != null){
result = listener.collide(node, node1);
}
if(listener1 != null && node.getCollisionGroup() != node1.getCollisionGroup()){
result = listener1.collide(node, node1) && result;
}
return result;
}
/**
* updates the physics space
*

@ -238,11 +238,11 @@ public class PhysicsSpace {
PhysicsCollisionGroupListener listener = collisionGroupListeners.get(collisionObject.getCollisionGroup());
PhysicsCollisionGroupListener listener1 = collisionGroupListeners.get(collisionObject1.getCollisionGroup());
if(listener != null){
return listener.collide(collisionObject, collisionObject1);
} else if (listener1 != null) {
return listener1.collide(collisionObject, collisionObject1);
collides = listener.collide(collisionObject, collisionObject1);
}
if(listener1 != null && collisionObject.getCollisionGroup() != collisionObject1.getCollisionGroup()){
collides = listener1.collide(collisionObject, collisionObject1) && collides;
}
return true;
} else {
return false;
}

Loading…
Cancel
Save