Native bullet ray request

It works, but it is not good as it is… Cause it currently needs to get the methodids and similar for each hit a ray takes. This should be optimized, but there happens the problem i mentioned.



I hope normen gets some free time, and an take a look if he can give an example of how that should be done, then I can do the rest. I tried to mimic the other classes in there, but whenever I do this I get access exceptions.

Here it is, cleaned up and working.



Also fixed a potential bug, taht was causing me the problems.

in jmeclasses the jclass objects are cached. This is not valid, since the jvm will clean those up when returning from jni → causing access violations when trying to use them.

fixed that by telling the jvm to explicitly keep those.

Also changed some headers, to allow circles in dependencys, since the rays need that.



Patch is tested and works with jme version 8571





[patch]Index: src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp

===================================================================

— src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp (revision 8571)

+++ src/bullet/native/com_jme3_bullet_PhysicsSpace.cpp (working copy)

@@ -396,6 +396,59 @@

delete(space);

}



+

+

+

  • JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_rayTest_1native
  • (JNIEnv * env,jobject object, jobject to,jobject from,jlong spaceId,jobject resultlist) {

    +
  •   jmePhysicsSpace* space = reinterpret_cast&lt;jmePhysicsSpace*&gt;(spaceId);<br />
    
  •   if(space == NULL){<br />
    
  •    	jclass newExc = env-&gt;FindClass(&quot;java/lang/NullPointerException&quot;);<br />
    
  •        env-&gt;ThrowNew(newExc, &quot;Physicspace null native geht&quot;);<br />
    
  •        return;<br />
    
  •   }<br />
    

+

  •   struct	AllRayResultCallback : public btCollisionWorld::RayResultCallback<br />
    
  •   {<br />
    
  •   	AllRayResultCallback(const btVector3&amp;	rayFromWorld,const btVector3&amp;	rayToWorld):m_rayFromWorld(rayFromWorld),m_rayToWorld(rayToWorld){<br />
    
  •   	}<br />
    
  •   	jobject resultlist;<br />
    
  •   	JNIEnv* env;<br />
    
  •   	btVector3	m_rayFromWorld;//used to calculate hitPointWorld from hitFraction<br />
    
  •   	btVector3	m_rayToWorld;<br />
    

+

  •   	btVector3	m_hitNormalWorld;<br />
    
  •   	btVector3	m_hitPointWorld;<br />
    

+

  •   	virtual	btScalar	addSingleResult(btCollisionWorld::LocalRayResult&amp; rayResult,bool normalInWorldSpace)<br />
    
  •   	{<br />
    
  •   		if (normalInWorldSpace){<br />
    
  •   			m_hitNormalWorld = rayResult.m_hitNormalLocal;<br />
    
  •   		} else	{<br />
    
  •   			m_hitNormalWorld = m_collisionObject-&gt;getWorldTransform().getBasis()*rayResult.m_hitNormalLocal;<br />
    
  •   		}<br />
    
  •   		m_hitPointWorld.setInterpolate3(m_rayFromWorld,m_rayToWorld,rayResult.m_hitFraction);<br />
    

+

  •   	    jmeBulletUtil::addResult(env, resultlist,m_hitNormalWorld,m_hitPointWorld,rayResult.m_hitFraction,rayResult.m_collisionObject);<br />
    

+

  •   		return 1.f;<br />
    
  •   	}<br />
    
  •   };<br />
    

+

  •    btVector3 native_to = btVector3();<br />
    
  •    jmeBulletUtil::convert(env, to, &amp;native_to);<br />
    

+

  •    btVector3 native_from = btVector3();<br />
    
  •    jmeBulletUtil::convert(env, from, &amp;native_from);<br />
    

+

  •   AllRayResultCallback resultCallback(native_from,native_to);<br />
    
  •   resultCallback.env = env;<br />
    
  •   resultCallback.resultlist = resultlist;<br />
    
  •   space-&gt;getDynamicsWorld()-&gt;rayTest (native_from,native_to, resultCallback);<br />
    
  •    return;<br />
    
  • }

    +

    #ifdef __cplusplus

    }

    #endif

    Index: src/bullet/native/jmeUserPointer.h

    ===================================================================

    — src/bullet/native/jmeUserPointer.h (revision 8571)

    +++ src/bullet/native/jmeUserPointer.h (working copy)

    @@ -1,6 +1,7 @@

    #ifndef _Included_jmeUserPointer

    #define _Included_jmeUserPointer

    #include <jni.h>

    +#include "jmePhysicsSpace.h"

    class jmeUserPointer {

    public:

    jobject javaCollisionObject;

    @@ -8,4 +9,4 @@

    jint groups;

    jmePhysicsSpace *space;

    };

    -#endif

    No newline at end of file

    +#endif

    Index: src/bullet/native/jmeMotionState.h

    ===================================================================

    — src/bullet/native/jmeMotionState.h (revision 8571)

    +++ src/bullet/native/jmeMotionState.h (working copy)

    @@ -29,13 +29,18 @@
  • NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  • SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    */

    +

    +#ifndef _Included_jmeMotionState

    +#define _Included_jmeMotionState

    #include <jni.h>



    /**
    • Author: Normen Hansen
    • Author: Normen Hansen,Empire Phoenix, Lutherion

      */



      #include "btBulletDynamicsCommon.h"

      +#include "jmePhysicsSpace.h"

      +#endif

      //#include "btBulletCollisionCommon.h"



      class jmeMotionState : public btMotionState {

      Index: src/bullet/native/jmeClasses.h

      ===================================================================

      — src/bullet/native/jmeClasses.h (revision 8571)

      +++ src/bullet/native/jmeClasses.h (working copy)

      @@ -29,10 +29,13 @@
  • NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  • SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    */

    +

    +#ifndef _Included_jmeClasses

    +#define _Included_jmeClasses

    #include <jni.h>



    /**
    • Author: Normen Hansen
    • Author: Normen Hansen,Empire Phoenix, Lutherion

      */



      class jmeClasses {

      @@ -84,8 +87,16 @@

      static jclass DebugMeshCallback;

      static jmethodID DebugMeshCallback_addVector;


  • static jclass PhysicsRay_Class;
  • static jmethodID PhysicsRay_newSingleResult;
  • static jfieldID PhysicsRay_normalInWorldSpace;
  • static jfieldID PhysicsRay_hitfraction;
  • static jfieldID PhysicsRay_collisionObject;
  • static jclass PhysicsRay_listresult;
  • static jmethodID PhysicsRay_addmethod;

    static void throwNPE(JNIEnv* env);

    private:

    jmeClasses(){};

    ~jmeClasses(){};

    -};

    No newline at end of file

    +};

    +#endif

    Index: src/bullet/native/com_jme3_bullet_PhysicsSpace_BroadphaseType.h

    ===================================================================

    — src/bullet/native/com_jme3_bullet_PhysicsSpace_BroadphaseType.h (revision 0)

    +++ src/bullet/native/com_jme3_bullet_PhysicsSpace_BroadphaseType.h (revision 0)

    @@ -0,0 +1,13 @@

    +/* DO NOT EDIT THIS FILE - it is machine generated /

    +#include <jni.h>

    +/
    Header for class com_jme3_bullet_PhysicsSpace_BroadphaseType */

    +

    +#ifndef _Included_com_jme3_bullet_PhysicsSpace_BroadphaseType

    +#define _Included_com_jme3_bullet_PhysicsSpace_BroadphaseType

    +#ifdef __cplusplus

    +extern "C" {

    +#endif

    +#ifdef __cplusplus

    +}

    +#endif

    +#endif

    Index: src/bullet/native/jmeClasses.cpp

    ===================================================================

    — src/bullet/native/jmeClasses.cpp (revision 8571)

    +++ src/bullet/native/jmeClasses.cpp (working copy)

    @@ -33,7 +33,7 @@

    #include <stdio.h>



    /**
    • Author: Normen Hansen
    • Author: Normen Hansen,Empire Phoenix, Lutherion

      /

      //public fields

      jclass jmeClasses::PhysicsSpace;

      @@ -81,6 +81,16 @@

      jclass jmeClasses::DebugMeshCallback;

      jmethodID jmeClasses::DebugMeshCallback_addVector;



      +jclass jmeClasses::PhysicsRay_Class;

      +jmethodID jmeClasses::PhysicsRay_newSingleResult;

      +

      +jfieldID jmeClasses::PhysicsRay_normalInWorldSpace;

      +jfieldID jmeClasses::PhysicsRay_hitfraction;

      +jfieldID jmeClasses::PhysicsRay_collisionObject;

      +

      +jclass jmeClasses::PhysicsRay_listresult;

      +jmethodID jmeClasses::PhysicsRay_addmethod;

      +

      //private fields

      //JNIEnv
      jmeClasses::env;

      JavaVM* jmeClasses::vm;

      @@ -103,7 +113,7 @@

      // jmeClasses::env = env;

      env->GetJavaVM(&vm);


  • PhysicsSpace = env->FindClass("com/jme3/bullet/PhysicsSpace");
  • PhysicsSpace = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/PhysicsSpace"));

    if (env->ExceptionCheck()) {

    env->Throw(env->ExceptionOccurred());

    return;

    @@ -117,7 +127,7 @@

    return;

    }


  • PhysicsGhostObject = env->FindClass("com/jme3/bullet/objects/PhysicsGhostObject");
  • PhysicsGhostObject = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/objects/PhysicsGhostObject"));

    if (env->ExceptionCheck()) {

    env->Throw(env->ExceptionOccurred());

    return;

    @@ -128,7 +138,7 @@

    return;

    }


  • Vector3f = env->FindClass("com/jme3/math/Vector3f");
  • Vector3f = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Vector3f"));

    Vector3f_set = env->GetMethodID(Vector3f, "set", "(FFF)Lcom/jme3/math/Vector3f;");

    Vector3f_toArray = env->GetMethodID(Vector3f, "toArray", "([F)[F");

    Vector3f_getX = env->GetMethodID(Vector3f, "getX", "()F");

    @@ -138,7 +148,7 @@

    Vector3f_y = env->GetFieldID(Vector3f, "y", "F");

    Vector3f_z = env->GetFieldID(Vector3f, "z", "F");


  • Quaternion = env->FindClass("com/jme3/math/Quaternion");
  • Quaternion = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Quaternion"));

    if (env->ExceptionCheck()) {

    env->Throw(env->ExceptionOccurred());

    return;

    @@ -153,7 +163,7 @@

    Quaternion_z = env->GetFieldID(Quaternion, "z", "F");

    Quaternion_w = env->GetFieldID(Quaternion, "w", "F");


  • Matrix3f = env->FindClass("com/jme3/math/Matrix3f");
  • Matrix3f = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/math/Matrix3f"));

    if (env->ExceptionCheck()) {

    env->Throw(env->ExceptionOccurred());

    return;

    @@ -174,17 +184,62 @@

    Matrix3f_m21 = env->GetFieldID(Matrix3f, "m21", "F");

    Matrix3f_m22 = env->GetFieldID(Matrix3f, "m22", "F");


  • DebugMeshCallback = env->FindClass("com/jme3/bullet/util/DebugMeshCallback");
  • DebugMeshCallback = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/util/DebugMeshCallback"));

    if (env->ExceptionCheck()) {

    env->Throw(env->ExceptionOccurred());

    return;

    }

    -

    +

    DebugMeshCallback_addVector = env->GetMethodID(DebugMeshCallback, "addVector", "(FFFII)V");

    if (env->ExceptionCheck()) {

    env->Throw(env->ExceptionOccurred());

    return;

    }

    +
  • PhysicsRay_Class = (jclass)env->NewGlobalRef(env->FindClass("com/jme3/bullet/collision/PhysicsRayTestResult"));
  • if (env->ExceptionCheck()) {
  •    env-&gt;Throw(env-&gt;ExceptionOccurred());<br />
    
  •    return;<br />
    
  • }

    +
  • PhysicsRay_newSingleResult = env->GetMethodID(PhysicsRay_Class,"<init>","()V");
  • if (env->ExceptionCheck()) {
  •    env-&gt;Throw(env-&gt;ExceptionOccurred());<br />
    
  •    return;<br />
    
  • }

    +
  • PhysicsRay_normalInWorldSpace = env->GetFieldID(PhysicsRay_Class,"hitNormalLocal","Lcom/jme3/math/Vector3f;");
  •    if (env-&gt;ExceptionCheck()) {<br />
    
  •        env-&gt;Throw(env-&gt;ExceptionOccurred());<br />
    
  •        return;<br />
    
  •    }<br />
    

+

+

  • PhysicsRay_hitfraction = env->GetFieldID(PhysicsRay_Class,"hitFraction","F");
  • if (env->ExceptionCheck()) {
  •    env-&gt;Throw(env-&gt;ExceptionOccurred());<br />
    
  •    return;<br />
    
  • }

    +

    +
  • PhysicsRay_collisionObject = env->GetFieldID(PhysicsRay_Class,"collisionObject","Lcom/jme3/bullet/collision/PhysicsCollisionObject;");
  • if (env->ExceptionCheck()) {
  •    env-&gt;Throw(env-&gt;ExceptionOccurred());<br />
    
  •    return;<br />
    
  • }

    +
  • PhysicsRay_listresult = env->FindClass("java/util/List");
  • PhysicsRay_listresult = (jclass)env->NewGlobalRef(PhysicsRay_listresult);
  • if (env->ExceptionCheck()) {
  •    env-&gt;Throw(env-&gt;ExceptionOccurred());<br />
    
  •    return;<br />
    
  • }

    +
  • PhysicsRay_addmethod = env->GetMethodID(PhysicsRay_listresult,"add","(Ljava/lang/Object;)Z");
  • if (env->ExceptionCheck()) {
  •    env-&gt;Throw(env-&gt;ExceptionOccurred());<br />
    
  •    return;<br />
    
  • }

    }



    void jmeClasses::throwNPE(JNIEnv* env) {

    Index: src/bullet/native/com_jme3_bullet_collision_PhysicsCollisionEvent.h

    ===================================================================

    — src/bullet/native/com_jme3_bullet_collision_PhysicsCollisionEvent.h (revision 8571)

    +++ src/bullet/native/com_jme3_bullet_collision_PhysicsCollisionEvent.h (working copy)

    @@ -8,7 +8,7 @@

    extern "C" {

    #endif

    #undef com_jme3_bullet_collision_PhysicsCollisionEvent_serialVersionUID

    -#define com_jme3_bullet_collision_PhysicsCollisionEvent_serialVersionUID 5516075349620653480LL

    +#define com_jme3_bullet_collision_PhysicsCollisionEvent_serialVersionUID 5516075349620653480i64

    #undef com_jme3_bullet_collision_PhysicsCollisionEvent_TYPE_ADDED

    #define com_jme3_bullet_collision_PhysicsCollisionEvent_TYPE_ADDED 0L

    #undef com_jme3_bullet_collision_PhysicsCollisionEvent_TYPE_PROCESSED

    Index: src/bullet/native/jmeBulletUtil.h

    ===================================================================

    — src/bullet/native/jmeBulletUtil.h (revision 8571)

    +++ src/bullet/native/jmeBulletUtil.h (working copy)

    @@ -29,13 +29,17 @@
  • NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  • SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    */

    +

    +#ifndef _Included_jmeBulletUtil

    +#define _Included_jmeBulletUtil

    #include "jmeClasses.h"

    #include "btBulletDynamicsCommon.h"

    #include "btBulletCollisionCommon.h"

    #include "LinearMath/btVector3.h"

    +#include "jmeUserPointer.h"



    /**
    • Author: Normen Hansen
    • Author: Normen Hansen,Empire Phoenix, Lutherion

      /

      class jmeBulletUtil{

      public:

      @@ -45,8 +49,10 @@

      static void convert(JNIEnv
      env, const btMatrix3x3* in, jobject out);

      static void convertQuat(JNIEnv* env, jobject in, btMatrix3x3* out);

      static void convertQuat(JNIEnv* env, const btMatrix3x3* in, jobject out);
  • static void addResult(JNIEnv* env, jobject resultlist, const btVector3 hitnormal,const btVector3 m_hitPointWorld,const btScalar m_hitFraction,btCollisionObject* hitobject);

    private:

    jmeBulletUtil(){};

    ~jmeBulletUtil(){};



    -};

    No newline at end of file

    +};

    +#endif

    Index: src/bullet/native/build.xml

    ===================================================================

    — src/bullet/native/build.xml (revision 8571)

    +++ src/bullet/native/build.xml (working copy)

    @@ -1,6 +1,7 @@

    <?xml version="1.0" encoding="UTF-8"?>

    -<project name="build bullet natives" default="all" basedir="…/…/…/">
  • <!-- load cpp compiler ant task -->

    +<project name="build bullet natives" basedir="…/…/…/">
  • <import file="${basedir}/build.xml"/>
  • <!-- load cpp compiler ant task -->

    <taskdef resource="cpptasks.tasks" classpath="lib/antlibs/cpptasks.jar"/>

    <!-- load properties -->

    <property file="src/bullet/native/bullet.properties"/>

    @@ -54,7 +55,11 @@

    </target>



    <target name="create-native-headers" description="creates the native headers">
  •    &lt;javah destdir=&quot;${bullet.source.dir}&quot; classpath=&quot;${bullet.build.dir}${path.separator}${lib.importpath}&quot; force=&quot;yes&quot;&gt;<br />
    
  •   &lt;echo message=&quot;${basedir}/build.xml&quot;&gt;&lt;/echo&gt;<br />
    

+

  •   &lt;antcall  target=&quot;default&quot;&gt;&lt;/antcall&gt;<br />
    

+

  •   &lt;javah destdir=&quot;${bullet.source.dir}&quot; classpath=&quot;${bullet.build.dir}${path.separator}${lib.importpath}&quot; force=&quot;yes&quot; verbose=&quot;yes&quot;&gt;<br />
    

<class name="com.jme3.bullet.PhysicsSpace"/>



<class name="com.jme3.bullet.collision.PhysicsCollisionEvent"/>

Index: src/bullet/native/jmeBulletUtil.cpp

===================================================================

— src/bullet/native/jmeBulletUtil.cpp (revision 8571)

+++ src/bullet/native/jmeBulletUtil.cpp (working copy)

@@ -33,7 +33,7 @@

#include "jmeBulletUtil.h"



/**

    • Author: Normen Hansen
    • Author: Normen Hansen,Empire Phoenix, Lutherion

      /

      void jmeBulletUtil::convert(JNIEnv
      env, jobject in, btVector3* out) {

      if (in == NULL || out == NULL) {

      @@ -306,3 +306,22 @@

      return;

      }

      }

      +

      +void jmeBulletUtil::addResult(JNIEnv* env, jobject resultlist, btVector3 hitnormal,btVector3 m_hitPointWorld,btScalar m_hitFraction,btCollisionObject* hitobject) {

      +
  • jobject singleresult = env->AllocObject(jmeClasses::PhysicsRay_Class);
  • jobject hitnormalvec = env->AllocObject(jmeClasses::Vector3f);

    +
  • convert(env,const_cast<btVector3*>(&hitnormal),hitnormalvec);
  • jmeUserPointer up1 = (jmeUserPointer)hitobject -> getUserPointer();

    +
  • env->SetObjectField(singleresult,jmeClasses::PhysicsRay_normalInWorldSpace,hitnormalvec);
  • env->SetFloatField(singleresult,jmeClasses::PhysicsRay_hitfraction,m_hitFraction);

    +
  • env->SetObjectField(singleresult,jmeClasses::PhysicsRay_collisionObject,up1->javaCollisionObject);
  • env->CallVoidMethod(resultlist,jmeClasses::PhysicsRay_addmethod,singleresult);
  • if (env->ExceptionCheck()) {
  •    env-&gt;Throw(env-&gt;ExceptionOccurred());<br />
    
  •    return;<br />
    
  • }

    +}

    Index: src/bullet/native/jmePhysicsSpace.h

    ===================================================================

    — src/bullet/native/jmePhysicsSpace.h (revision 8571)

    +++ src/bullet/native/jmePhysicsSpace.h (working copy)

    @@ -29,6 +29,8 @@
  • NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  • SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

    */

    +#ifndef _Included_jmePhysicsSpace

    +#define _Included_jmePhysicsSpace

    #include <jni.h>

    #include "btBulletDynamicsCommon.h"

    #include "btBulletCollisionCommon.h"

    @@ -50,7 +52,7 @@

    #include "BulletCollision/NarrowPhaseCollision/btPersistentManifold.h"



    /**
    • Author: Normen Hansen
    • Author: Normen Hansen,Empire Phoenix, Lutherion

      /

      class jmePhysicsSpace {

      private:

      @@ -73,4 +75,5 @@

      static void preTickCallback(btDynamicsWorld
      , btScalar);

      static void postTickCallback(btDynamicsWorld*, btScalar);

      static bool contactProcessedCallback(btManifoldPoint &, void *, void );

      -};

      No newline at end of file

      +};

      +#endif

      Index: src/bullet/native/com_jme3_bullet_PhysicsSpace.h

      ===================================================================

      — src/bullet/native/com_jme3_bullet_PhysicsSpace.h (revision 8571)

      +++ src/bullet/native/com_jme3_bullet_PhysicsSpace.h (working copy)

      @@ -1,157 +0,0 @@

      -/
      DO NOT EDIT THIS FILE - it is machine generated /

      -#include <jni.h>

      -/
      Header for class com_jme3_bullet_PhysicsSpace /

      -

      -#ifndef _Included_com_jme3_bullet_PhysicsSpace

      -#define _Included_com_jme3_bullet_PhysicsSpace

      -#ifdef __cplusplus

      -extern "C" {

      -#endif

      -#undef com_jme3_bullet_PhysicsSpace_AXIS_X

      -#define com_jme3_bullet_PhysicsSpace_AXIS_X 0L

      -#undef com_jme3_bullet_PhysicsSpace_AXIS_Y

      -#define com_jme3_bullet_PhysicsSpace_AXIS_Y 1L

      -#undef com_jme3_bullet_PhysicsSpace_AXIS_Z

      -#define com_jme3_bullet_PhysicsSpace_AXIS_Z 2L

      -/
      Inaccessible static: pQueueTL /

      -/
      Inaccessible static: physicsSpaceTL /

      -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: createPhysicsSpace
    • Signature: (FFFFFFIZ)J
  • */

    -JNIEXPORT jlong JNICALL Java_com_jme3_bullet_PhysicsSpace_createPhysicsSpace
  • (JNIEnv , jobject, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jint, jboolean);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: stepSimulation
    • Signature: (JFIF)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_stepSimulation
  • (JNIEnv , jobject, jlong, jfloat, jint, jfloat);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: addCollisionObject
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addCollisionObject
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: removeCollisionObject
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeCollisionObject
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: addRigidBody
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addRigidBody
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: removeRigidBody
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeRigidBody
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: addCharacterObject
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addCharacterObject
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: removeCharacterObject
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeCharacterObject
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: addAction
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addAction
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: removeAction
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeAction
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: addVehicle
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addVehicle
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: removeVehicle
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeVehicle
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: addConstraint
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_addConstraint
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: removeConstraint
    • Signature: (JJ)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_removeConstraint
  • (JNIEnv , jobject, jlong, jlong);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: setGravity
    • Signature: (JLcom/jme3/math/Vector3f;)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setGravity
  • (JNIEnv , jobject, jlong, jobject);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: initNativePhysics
    • Signature: ()V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_initNativePhysics
  • (JNIEnv , jclass);

    -

    -/

    • Class: com_jme3_bullet_PhysicsSpace
    • Method: finalizeNative
    • Signature: (J)V
  • */

    -JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_finalizeNative
  • (JNIEnv *, jobject, jlong);

    -

    -#ifdef __cplusplus

    -}

    -#endif

    -#endif

    Index: src/bullet/com/jme3/bullet/joints/SliderJoint.java

    ===================================================================

    — src/bullet/com/jme3/bullet/joints/SliderJoint.java (revision 8571)

    +++ src/bullet/com/jme3/bullet/joints/SliderJoint.java (working copy)

    @@ -35,7 +35,6 @@

    import com.jme3.math.Matrix3f;

    import com.jme3.math.Vector3f;

    import com.jme3.bullet.objects.PhysicsRigidBody;

    -import com.jme3.bullet.util.Converter;

    import com.jme3.export.InputCapsule;

    import com.jme3.export.JmeImporter;

    import com.jme3.export.OutputCapsule;

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

    ===================================================================

    — src/bullet/com/jme3/bullet/collision/PhysicsRayTestResult.java (revision 8571)

    +++ src/bullet/com/jme3/bullet/collision/PhysicsRayTestResult.java (working copy)

    @@ -35,23 +35,21 @@



    /**
  • Contains the results of a PhysicsSpace rayTest
    • @author normenhansen
    • bulletAppState.getPhysicsSpace().rayTest(new Vector3f(0,1000,0),new Vector3f(0,-1000,0));
  • javap -s java.util.List
    • @author Empire-Phoenix,normenhansen

      */

      public class PhysicsRayTestResult {

      -

      +

      private PhysicsCollisionObject collisionObject;

      private Vector3f hitNormalLocal;

      private float hitFraction;
  • private boolean normalInWorldSpace;

    -
  • public PhysicsRayTestResult() {
  • }
  • private boolean normalInWorldSpace = true;


  • public PhysicsRayTestResult(PhysicsCollisionObject collisionObject, Vector3f hitNormalLocal, float hitFraction, boolean normalInWorldSpace) {
  •    this.collisionObject = collisionObject;<br />
    
  •    this.hitNormalLocal = hitNormalLocal;<br />
    
  •    this.hitFraction = hitFraction;<br />
    
  •    this.normalInWorldSpace = normalInWorldSpace;<br />
    
  • /**
  • * allocated by native code only<br />
    
  • */<br />
    
  • private PhysicsRayTestResult() {

    }



    /**

    @@ -81,11 +79,4 @@

    public boolean isNormalInWorldSpace() {

    return normalInWorldSpace;

    }

    -
  • public void fill(PhysicsCollisionObject collisionObject, Vector3f hitNormalLocal, float hitFraction, boolean normalInWorldSpace) {
  •    this.collisionObject = collisionObject;<br />
    
  •    this.hitNormalLocal = hitNormalLocal;<br />
    
  •    this.hitFraction = hitFraction;<br />
    
  •    this.normalInWorldSpace = normalInWorldSpace;<br />
    
  • }

    }

    Index: src/bullet/com/jme3/bullet/PhysicsSpace.java

    ===================================================================

    — src/bullet/com/jme3/bullet/PhysicsSpace.java (revision 8571)

    +++ src/bullet/com/jme3/bullet/PhysicsSpace.java (working copy)

    @@ -715,17 +715,31 @@

    /**
  • Performs a ray collision test and returns the results as a list of PhysicsRayTestResults

    */
  • public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to) {
  •    List&lt;PhysicsRayTestResult&gt; results = new LinkedList&lt;PhysicsRayTestResult&gt;();<br />
    

-// dynamicsWorld.rayTest(Converter.convert(from, rayVec1), Converter.convert(to, rayVec2), new InternalRayListener(results));

  • public List rayTest(Vector3f from, Vector3f to) {
  •   System.out.println(&quot;Doing ray&quot;);<br />
    
  •   List results = new LinkedList();<br />
    
  •    rayTest(from,to,results);<br />
    

+

  •    List&lt;PhysicsRayTestResult&gt; resulttscastet = results;<br />
    
  •    for(PhysicsRayTestResult res:resulttscastet){<br />
    
  •    	System.out.println(&quot;RayResult &quot; + res.getHitNormalLocal());<br />
    
  •    	System.out.println(&quot;RayResult &quot; + res.getHitFraction());<br />
    
  •    	if(res.getCollisionObject() != null){<br />
    
  •    		if(res.getCollisionObject().getUserObject() != null){<br />
    
  •    			System.out.println(&quot;RayResult &quot; + res.getCollisionObject().getUserObject().toString());<br />
    
  •        	}<br />
    
  •    	}<br />
    
  •    }<br />
    

return results;

}



+

/**

  • Performs a ray collision test and returns the results as a list of PhysicsRayTestResults

    */

    public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) {

    results.clear();
  •    rayTest_native(from,to,physicsSpaceId,results);<br />
    

// dynamicsWorld.rayTest(Converter.convert(from, rayVec1), Converter.convert(to, rayVec2), new InternalRayListener(results));

return results;

}

@@ -884,6 +898,9 @@

public void disableDebug() {

debugManager = null;

}

+

  • public native void rayTest_native(Vector3f from,Vector3f to,long physicsSpaceId, List<PhysicsRayTestResult> results);

    +



    public AssetManager getDebugManager() {

    return debugManager;

    [/patch]
2 Likes

Alright, cool, thanks! You’re right, jclass references are handled different than method and object id’s. So when the class would be unloaded by java the reference dies too… I don’t want the “BroadphaseType” class to be wrapped though, for bridging the differences between native and jbullet there will be another way to configure the PhysicsSpace, similar to AppSettings… I’ll have a whack at putting this stuff in tomorrow, I should have some time then.

Ok, I cleaned and committed it: http://code.google.com/p/jmonkeyengine/source/detail?r=8577

Committing the OSX multi platform binary and 32bit windows dll now, linux 64bit should be added by the nightly build server.