Minor Native Bullet Fixes

Hello everyone,

For my current project, I recently switched from JBullet to native bullet and encountered some weirdness in the process. I even filed a bug report. But since this issue is really trivial to fix, I thought I’d simply do it myself. I also added a fix for another issue I encountered.

The patch, included below, fixes the issue linked above, namely that the getPositionWorldOnA(Vector3f) method of the PhysicsCollisionEvent class will call itself recursively and loop forever.

It also fixes a small issue in the ray test. The native jME physics space takes the hit normals returned by the native ray test and always converts them into world coordinates. But the boolean flag normalInWorldSpace in the PhysicsRayTestResult is never set and wrongly defaults to false.

The patch was done against the current svn trunk. It really nothing special, but I hope it saves you guys some work. :slight_smile:
I compiled and tested the changes on my linux system and they work fine.


Index: src/bullet/com/jme3/bullet/collision/PhysicsCollisionEvent.java

— src/bullet/com/jme3/bullet/collision/PhysicsCollisionEvent.java (revision 11115)
+++ src/bullet/com/jme3/bullet/collision/PhysicsCollisionEvent.java (working copy)
@@ -229,7 +229,7 @@
}

 public Vector3f getPositionWorldOnA(Vector3f positionWorldOnA) {
  •    getPositionWorldOnA(positionWorldOnA);
    
  •    getPositionWorldOnA(manifoldPointObjectId, positionWorldOnA);
       return positionWorldOnA;
    

    }
    private native void getPositionWorldOnA(long manifoldPointObjectId, Vector3f positionWorldOnA);
    Index: src/bullet-native/jmeBulletUtil.cpp
    ===================================================================
    — src/bullet-native/jmeBulletUtil.cpp (revision 11115)
    +++ src/bullet-native/jmeBulletUtil.cpp (working copy)
    @@ -316,6 +318,7 @@
    jmeUserPointer up1 = (jmeUserPointer) hitobject -> getUserPointer();

    env->SetObjectField(singleresult, jmeClasses::PhysicsRay_normalInWorldSpace, hitnormalvec);

  • env->SetBooleanField(singleresult, jmeClasses::PhysicsRay_isNormalInWorldSpace, true);
    env->SetFloatField(singleresult, jmeClasses::PhysicsRay_hitfraction, m_hitFraction);

    env->SetObjectField(singleresult, jmeClasses::PhysicsRay_collisionObject, up1->javaCollisionObject);
    Index: src/bullet-native/jmeClasses.cpp
    ===================================================================
    — src/bullet-native/jmeClasses.cpp (revision 11115)
    +++ src/bullet-native/jmeClasses.cpp (working copy)
    @@ -85,6 +85,7 @@
    jmethodID jmeClasses::PhysicsRay_newSingleResult;

jfieldID jmeClasses::PhysicsRay_normalInWorldSpace;
+jfieldID jmeClasses::PhysicsRay_isNormalInWorldSpace;
jfieldID jmeClasses::PhysicsRay_hitfraction;
jfieldID jmeClasses::PhysicsRay_collisionObject;

@@ -214,6 +215,11 @@
return;
}

  • PhysicsRay_isNormalInWorldSpace = env->GetFieldID(PhysicsRay_Class,“normalInWorldSpace”,“Z”);

  •    if (env->ExceptionCheck()) {
    
  •        env->Throw(env->ExceptionOccurred());
    
  •        return;
    
  •    }
    

    PhysicsRay_hitfraction = env->GetFieldID(PhysicsRay_Class,“hitFraction”,“F”);
    if (env->ExceptionCheck()) {
    Index: src/bullet-native/jmeClasses.h
    ===================================================================
    — src/bullet-native/jmeClasses.h (revision 11115)
    +++ src/bullet-native/jmeClasses.h (working copy)
    @@ -84,6 +84,7 @@
    static jclass PhysicsRay_Class;
    static jmethodID PhysicsRay_newSingleResult;
    static jfieldID PhysicsRay_normalInWorldSpace;

  • static jfieldID PhysicsRay_isNormalInWorldSpace;
    static jfieldID PhysicsRay_hitfraction;
    static jfieldID PhysicsRay_collisionObject;
    static jclass PhysicsRay_listresult;

4 Likes

We moved to GitHub, so please repost your issue in our new issue tracker, and feel free to make a pull request.