fix issue #1029, integrate PR #1031

* Use gContactStartedCallback instead of gContactProcessedCallback to detect collision events. ( fix for #1029 )

* Fix  Conversion loses qualifiers
accellbaker
Riccardo Balbo 6 years ago committed by Stephen Gold
parent 7e6fa03009
commit 2bbf784c96
  1. 23
      jme3-bullet-native/src/native/cpp/jmePhysicsSpace.cpp
  2. 2
      jme3-bullet-native/src/native/cpp/jmePhysicsSpace.h

@ -150,8 +150,8 @@ void jmePhysicsSpace::createPhysicsSpace(jfloat minX, jfloat minY, jfloat minZ,
dynamicsWorld->getPairCache()->setOverlapFilterCallback(new jmeFilterCallback());
dynamicsWorld->setInternalTickCallback(&jmePhysicsSpace::preTickCallback, static_cast<void *> (this), true);
dynamicsWorld->setInternalTickCallback(&jmePhysicsSpace::postTickCallback, static_cast<void *> (this));
if (gContactProcessedCallback == NULL) {
gContactProcessedCallback = &jmePhysicsSpace::contactProcessedCallback;
if (gContactStartedCallback == NULL) {
gContactStartedCallback = &jmePhysicsSpace::contactStartedCallback;
}
}
@ -183,11 +183,10 @@ void jmePhysicsSpace::postTickCallback(btDynamicsWorld *world, btScalar timeStep
}
}
bool jmePhysicsSpace::contactProcessedCallback(btManifoldPoint &cp, void *body0, void *body1) {
// printf("contactProcessedCallback %d %dn", body0, body1);
btCollisionObject* co0 = (btCollisionObject*) body0;
void jmePhysicsSpace::contactStartedCallback(btPersistentManifold* const &pm) {
const btCollisionObject* co0 = pm->getBody0();
const btCollisionObject* co1 = pm->getBody1();
jmeUserPointer *up0 = (jmeUserPointer*) co0 -> getUserPointer();
btCollisionObject* co1 = (btCollisionObject*) body1;
jmeUserPointer *up1 = (jmeUserPointer*) co1 -> getUserPointer();
if (up0 != NULL) {
jmePhysicsSpace *dynamicsWorld = (jmePhysicsSpace *)up0->space;
@ -197,18 +196,18 @@ bool jmePhysicsSpace::contactProcessedCallback(btManifoldPoint &cp, void *body0,
if (javaPhysicsSpace != NULL) {
jobject javaCollisionObject0 = env->NewLocalRef(up0->javaCollisionObject);
jobject javaCollisionObject1 = env->NewLocalRef(up1->javaCollisionObject);
env->CallVoidMethod(javaPhysicsSpace, jmeClasses::PhysicsSpace_addCollisionEvent, javaCollisionObject0, javaCollisionObject1, (jlong) & cp);
for(int i=0;i<pm->getNumContacts();i++){
env->CallVoidMethod(javaPhysicsSpace, jmeClasses::PhysicsSpace_addCollisionEvent, javaCollisionObject0, javaCollisionObject1, (jlong) & pm->getContactPoint(i));
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
}
}
env->DeleteLocalRef(javaPhysicsSpace);
env->DeleteLocalRef(javaCollisionObject0);
env->DeleteLocalRef(javaCollisionObject1);
if (env->ExceptionCheck()) {
env->Throw(env->ExceptionOccurred());
return true;
}
}
}
}
return true;
}
btDynamicsWorld* jmePhysicsSpace::getDynamicsWorld() {

@ -62,5 +62,5 @@ public:
JNIEnv* getEnv();
static void preTickCallback(btDynamicsWorld*, btScalar);
static void postTickCallback(btDynamicsWorld*, btScalar);
static bool contactProcessedCallback(btManifoldPoint &, void *, void *);
static void contactStartedCallback(btPersistentManifold* const &);
};
Loading…
Cancel
Save