// Create and destroy proxies. These call Flush first. int createProxy( AABB aabb, // int groupIndex, int categoryBits, int maskBits, Object userData) { if (debugPrint) { System.out.println("CreateProxy()"); } assert (m_proxyCount < Settings.maxProxies); assert (m_freeProxy != PairManager.NULL_PROXY); int proxyId = m_freeProxy; Proxy proxy = m_proxyPool[proxyId]; m_freeProxy = proxy.getNext(); proxy.overlapCount = 0; proxy.userData = userData; // proxy.groupIndex = groupIndex; // proxy.categoryBits = categoryBits; // proxy.maskBits = maskBits; // assert m_proxyCount < Settings.maxProxies; int boundCount = 2 * m_proxyCount; int lowerValues[] = new int[2]; int upperValues[] = new int[2]; computeBounds(lowerValues, upperValues, aabb); for (int axis = 0; axis < 2; ++axis) { Bound[] bounds = m_bounds[axis]; int[] indexes = new int[2]; query(indexes, lowerValues[axis], upperValues[axis], bounds, boundCount, axis); int lowerIndex = indexes[0]; int upperIndex = indexes[1]; // System.out.println(edgeCount + ", "+lowerValues[axis] + ", // "+upperValues[axis]); // memmove(bounds[upperIndex + 2], bounds[upperIndex], // (edgeCount - upperIndex) * sizeof(b2Bound)); System.arraycopy( m_bounds[axis], upperIndex, m_bounds[axis], upperIndex + 2, boundCount - upperIndex); for (int i = 0; i < boundCount - upperIndex; i++) { m_bounds[axis][upperIndex + 2 + i] = new Bound(m_bounds[axis][upperIndex + 2 + i]); } // memmove(bounds[lowerIndex + 1], bounds[lowerIndex], // (upperIndex - lowerIndex) * sizeof(b2Bound)); // System.out.println(lowerIndex+" "+upperIndex); System.arraycopy( m_bounds[axis], lowerIndex, m_bounds[axis], lowerIndex + 1, upperIndex - lowerIndex); for (int i = 0; i < upperIndex - lowerIndex; i++) { m_bounds[axis][lowerIndex + 1 + i] = new Bound(m_bounds[axis][lowerIndex + 1 + i]); } // The upper index has increased because of the lower bound // insertion. ++upperIndex; // Copy in the new bounds. // if (bounds[lowerIndex] == null) assert (bounds[lowerIndex] != null) : "Null pointer (lower)"; // if (bounds[upperIndex] == null) assert (bounds[upperIndex] != null) : "Null pointer (upper)"; bounds[lowerIndex].value = lowerValues[axis]; bounds[lowerIndex].proxyId = proxyId; bounds[upperIndex].value = upperValues[axis]; bounds[upperIndex].proxyId = proxyId; bounds[lowerIndex].stabbingCount = lowerIndex == 0 ? 0 : bounds[lowerIndex - 1].stabbingCount; bounds[upperIndex].stabbingCount = bounds[upperIndex - 1].stabbingCount; // System.out.printf("lv: %d , lid: %d, uv: %d, uid: %d // \n",lowerValues[axis],proxyId,upperValues[axis],proxyId); // Adjust the stabbing count between the new bounds. for (int index = lowerIndex; index < upperIndex; ++index) { ++bounds[index].stabbingCount; } // Adjust the all the affected bound indices. for (int index = lowerIndex; index < boundCount + 2; ++index) { Proxy proxyn = m_proxyPool[bounds[index].proxyId]; if (bounds[index].isLower()) { proxyn.lowerBounds[axis] = index; } else { proxyn.upperBounds[axis] = index; } } } ++m_proxyCount; assert m_queryResultCount < Settings.maxProxies; // Create pairs if the AABB is in range. for (int i = 0; i < m_queryResultCount; ++i) { assert (m_queryResults[i] < Settings.maxProxies); assert (m_proxyPool[m_queryResults[i]].isValid()); m_pairManager.addBufferedPair(proxyId, m_queryResults[i]); } m_pairManager.commit(); if (s_validate) { validate(); } // Prepare for next query. m_queryResultCount = 0; incrementTimeStamp(); return proxyId; }