Home | History | Annotate | Download | only in collision
      1 %module btBroadphasePairArray
      2 
      3 %include "../common/gdxDisableBuffers.i"
      4 %include "../common/gdxEnableCriticalArrays.i"
      5 
      6 %typemap(javacode) btAlignedObjectArray<btBroadphasePair> %{
      7 	/**
      8 	 * @param out The array to fill with collision objects
      9 	 * @param other The collision object the pair must contain (which itself is excluded from the result)
     10 	 * @param tempArray A temporary array used by the method, not more object than the length of this array are added
     11 	 * @return The array specified by out */
     12 	public com.badlogic.gdx.utils.Array<btCollisionObject> getCollisionObjects(final com.badlogic.gdx.utils.Array<btCollisionObject> out, final btCollisionObject other, final int[] tempArray) {
     13 		final int c = getCollisionObjects(tempArray, tempArray.length, (int)btCollisionObject.getCPtr(other));
     14 		for (int i = 0; i < c; i++)
     15 			out.add(btCollisionObject.getInstance(tempArray[i], false));
     16 		return out;
     17 	}
     18 
     19 	/** Fills the given array with user value set using {@link btCollisionObject#setUserValue(int)} of the collision objects
     20 	 * within this pair array colliding with the given collision object.
     21 	 * @param out The array to fill with the user values
     22 	 * @param other The collision object the pair must contain (which itself is excluded from the result)
     23 	 * @return The amount of user values set in the out array. */
     24 	public int getCollisionObjectsValue(final int[] out, final btCollisionObject other) {
     25 		return getCollisionObjectsValue(out, out.length, (int)btCollisionObject.getCPtr(other));
     26 	}
     27 %}
     28 
     29 %rename(btBroadphasePairArray) btAlignedObjectArray<btBroadphasePair>;
     30 class btAlignedObjectArray<btBroadphasePair> {
     31 public:
     32 	SIMD_FORCE_INLINE	int size() const;
     33 };
     34 
     35 %extend btAlignedObjectArray<btBroadphasePair> {
     36 
     37 	btBroadphasePair *at(int n) {
     38 		return &($self->at(n));
     39 	}
     40 
     41 	int getCollisionObjects(int result[], int max, int other) {
     42 		static btManifoldArray marr;
     43 		const int n = $self->size();
     44 		int count = 0;
     45 		int obj0, obj1;
     46 		for (int i = 0; i < n; i++) {
     47 			const btBroadphasePair& collisionPair = (*$self)[i];
     48 			if (collisionPair.m_algorithm) {
     49 				marr.resize(0);
     50 				collisionPair.m_algorithm->getAllContactManifolds(marr);
     51 				const int s = marr.size();
     52 				for (int j = 0; j < s; j++) {
     53 					btPersistentManifold *manifold = marr[j];
     54 					if (manifold->getNumContacts() > 0) {
     55 						*(const btCollisionObject **)&obj0 = manifold->getBody0();
     56 						*(const btCollisionObject **)&obj1 = manifold->getBody1();
     57 						if (obj0 == other)
     58 							result[count++] = obj1;
     59 						else if (obj1 == other)
     60 							result[count++] = obj0;
     61 						else continue;
     62 						if (count >= max)
     63 							return count;
     64 					}
     65 				}
     66 			}
     67 		}
     68 		return count;
     69 	}
     70 
     71 	int getCollisionObjectsValue(int result[], int max, int other) {
     72 		static btManifoldArray marr;
     73 		const int n = $self->size();
     74 		int count = 0;
     75 		int obj0, obj1;
     76 		for (int i = 0; i < n; i++) {
     77 			const btBroadphasePair& collisionPair = (*$self)[i];
     78 			if (collisionPair.m_algorithm) {
     79 				marr.resize(0);
     80 				collisionPair.m_algorithm->getAllContactManifolds(marr);
     81 				const int s = marr.size();
     82 				for (int j = 0; j < s; j++) {
     83 					btPersistentManifold *manifold = marr[j];
     84 					if (manifold->getNumContacts() > 0) {
     85 						*(const btCollisionObject **)&obj0 = manifold->getBody0();
     86 						*(const btCollisionObject **)&obj1 = manifold->getBody1();
     87 						if (obj0 == other)
     88 							result[count++] = ((GdxCollisionObjectBridge*)manifold->getBody1()->getUserPointer())->userValue;
     89 						else if (obj1 == other)
     90 							result[count++] = ((GdxCollisionObjectBridge*)manifold->getBody0()->getUserPointer())->userValue;
     91 						else continue;
     92 						if (count >= max)
     93 							return count;
     94 					}
     95 				}
     96 			}
     97 		}
     98 		return count;
     99 	}
    100 };
    101 
    102 %include "../common/gdxEnableBuffers.i"
    103