Home | History | Annotate | Download | only in collision
      1 %module btMultiSphereShape
      2 
      3 %include "../common/gdxDisableBuffers.i"
      4 %include "../common/gdxEnableArrays.i"
      5 
      6 %fragment("gdxBulletHelpersVector3Array", "header") {
      7 	btVector3* Vector3ArrayToBtVector3Array(JNIEnv * jenv, jobjectArray source) {
      8 		static jfieldID xField = NULL, yField = NULL, zField = NULL;
      9 		jint len = jenv->GetArrayLength(source);
     10 		if (len <= 0)
     11 			return NULL;
     12 
     13 		btVector3* result = new btVector3[len];
     14 
     15 		if (xField == NULL) {
     16 			jobject vec = jenv->GetObjectArrayElement(source, 0);
     17 			jclass sc = jenv->GetObjectClass(vec);
     18 			xField = jenv->GetFieldID(sc, "x", "F");
     19 			yField = jenv->GetFieldID(sc, "y", "F");
     20 			zField = jenv->GetFieldID(sc, "z", "F");
     21 			jenv->DeleteLocalRef(sc);
     22 		}
     23 
     24 		for (int i = 0; i < len; i++) {
     25 			jobject vec = jenv->GetObjectArrayElement(source, i);
     26 			result[i].setValue(jenv->GetFloatField(vec, xField), jenv->GetFloatField(vec, yField), jenv->GetFloatField(vec, zField));
     27 		}
     28 		return result;
     29 	}
     30 
     31 	class gdxAutoDeleteBtVector3Array {
     32 	private:
     33 	  btVector3* array;
     34 	public:
     35 	  gdxAutoDeleteBtVector3Array(btVector3* arr) :
     36 	    array(arr) { }
     37 	  virtual ~gdxAutoDeleteBtVector3Array() {
     38 		  if (array != NULL)
     39 			  delete[] array;
     40 	  }
     41 	};
     42 }
     43 
     44 %typemap(jstype) 			btVector3* 	"Vector3[]"
     45 %typemap(jtype) 			btVector3* 	"Vector3[]"
     46 %typemap(javain)			btVector3*	"$javainput"
     47 %typemap(jni) 				btVector3* 	"jobjectArray"
     48 
     49 %typemap(in, fragment="gdxBulletHelpersVector3Array", noblock=1)		btVector3*	{
     50 	static jfieldID xField = NULL, yField = NULL, zField = NULL;
     51 	$1 = Vector3ArrayToBtVector3Array(jenv, $input);
     52 	gdxAutoDeleteBtVector3Array auto_delete($1);
     53 }
     54 
     55 %{
     56 #include <BulletCollision/CollisionShapes/btMultiSphereShape.h>
     57 %}
     58 %include "BulletCollision/CollisionShapes/btMultiSphereShape.h"
     59 
     60 %clear btVector3*;
     61 %include "../common/gdxDisableArrays.i"
     62 %include "../common/gdxEnableBuffers.i"