use of com.bulletphysics.util.ObjectArrayList in project bdx by GoranM.
the class Dbvt method collideOCL.
public static void collideOCL(Node root, Vector3f[] normals, float[] offsets, Vector3f sortaxis, int count, ICollide policy, boolean fullsort) {
//DBVT_CHECKTYPE
if (root != null) {
int srtsgns = (sortaxis.x >= 0 ? 1 : 0) + (sortaxis.y >= 0 ? 2 : 0) + (sortaxis.z >= 0 ? 4 : 0);
int inside = (1 << count) - 1;
ObjectArrayList<sStkNPS> stock = new ObjectArrayList<sStkNPS>();
IntArrayList ifree = new IntArrayList();
IntArrayList stack = new IntArrayList();
int[] signs = new int[/*sizeof(unsigned)*8*/
4 * 8];
assert (count < (/*sizeof(signs)*/
128 / /*sizeof(signs[0])*/
4));
for (int i = 0; i < count; i++) {
signs[i] = ((normals[i].x >= 0) ? 1 : 0) + ((normals[i].y >= 0) ? 2 : 0) + ((normals[i].z >= 0) ? 4 : 0);
}
//stock.reserve(SIMPLE_STACKSIZE);
//stack.reserve(SIMPLE_STACKSIZE);
//ifree.reserve(SIMPLE_STACKSIZE);
stack.add(allocate(ifree, stock, new sStkNPS(root, 0, root.volume.ProjectMinimum(sortaxis, srtsgns))));
do {
// JAVA NOTE: check
int id = stack.remove(stack.size() - 1);
sStkNPS se = stock.getQuick(id);
ifree.add(id);
if (se.mask != inside) {
boolean out = false;
for (int i = 0, j = 1; (!out) && (i < count); ++i, j <<= 1) {
if (0 == (se.mask & j)) {
int side = se.node.volume.Classify(normals[i], offsets[i], signs[i]);
switch(side) {
case -1:
out = true;
break;
case +1:
se.mask |= j;
break;
}
}
}
if (out) {
continue;
}
}
if (policy.Descent(se.node)) {
if (se.node.isinternal()) {
Node[] pns = new Node[] { se.node.childs[0], se.node.childs[1] };
sStkNPS[] nes = new sStkNPS[] { new sStkNPS(pns[0], se.mask, pns[0].volume.ProjectMinimum(sortaxis, srtsgns)), new sStkNPS(pns[1], se.mask, pns[1].volume.ProjectMinimum(sortaxis, srtsgns)) };
int q = nes[0].value < nes[1].value ? 1 : 0;
int j = stack.size();
if (fullsort && (j > 0)) {
/* Insert 0 */
j = nearest(stack, stock, nes[q].value, 0, stack.size());
stack.add(0);
//#else
for (int k = stack.size() - 1; k > j; --k) {
stack.set(k, stack.get(k - 1));
//#endif
}
stack.set(j, allocate(ifree, stock, nes[q]));
/* Insert 1 */
j = nearest(stack, stock, nes[1 - q].value, j, stack.size());
stack.add(0);
//#else
for (int k = stack.size() - 1; k > j; --k) {
stack.set(k, stack.get(k - 1));
//#endif
}
stack.set(j, allocate(ifree, stock, nes[1 - q]));
} else {
stack.add(allocate(ifree, stock, nes[q]));
stack.add(allocate(ifree, stock, nes[1 - q]));
}
} else {
policy.Process(se.node, se.value);
}
}
} while (stack.size() != 0);
}
}
use of com.bulletphysics.util.ObjectArrayList in project bdx by GoranM.
the class Dbvt method collideTV.
public static void collideTV(Node root, DbvtAabbMm volume, ICollide policy) {
//DBVT_CHECKTYPE
if (root != null) {
ObjectArrayList<Node> stack = new ObjectArrayList<Node>(SIMPLE_STACKSIZE);
stack.add(root);
do {
Node n = stack.remove(stack.size() - 1);
if (DbvtAabbMm.Intersect(n.volume, volume)) {
if (n.isinternal()) {
stack.add(n.childs[0]);
stack.add(n.childs[1]);
} else {
policy.Process(n);
}
}
} while (stack.size() > 0);
}
}
use of com.bulletphysics.util.ObjectArrayList in project bdx by GoranM.
the class Dbvt method collideTU.
public static void collideTU(Node root, ICollide policy) {
//DBVT_CHECKTYPE
if (root != null) {
ObjectArrayList<Node> stack = new ObjectArrayList<Node>(SIMPLE_STACKSIZE);
stack.add(root);
do {
Node n = stack.remove(stack.size() - 1);
if (policy.Descent(n)) {
if (n.isinternal()) {
stack.add(n.childs[0]);
stack.add(n.childs[1]);
} else {
policy.Process(n);
}
}
} while (stack.size() > 0);
}
}
use of com.bulletphysics.util.ObjectArrayList in project bdx by GoranM.
the class Dbvt method topdown.
private static Node topdown(Dbvt pdbvt, ObjectArrayList<Node> leaves, int bu_treshold) {
if (leaves.size() > 1) {
if (leaves.size() > bu_treshold) {
Stack stack = Stack.enter();
DbvtAabbMm vol = bounds(leaves);
Vector3f org = vol.Center(stack.allocVector3f());
ObjectArrayList[] sets = new ObjectArrayList[2];
for (int i = 0; i < sets.length; i++) {
sets[i] = new ObjectArrayList();
}
int bestaxis = -1;
int bestmidp = leaves.size();
int[][] splitcount = new int[][] { { 0, 0 }, { 0, 0 }, { 0, 0 } };
Vector3f x = stack.allocVector3f();
for (int i = 0; i < leaves.size(); i++) {
leaves.getQuick(i).volume.Center(x);
x.sub(org);
for (int j = 0; j < 3; j++) {
splitcount[j][x.dot(axis[j]) > 0f ? 1 : 0]++;
}
}
for (int i = 0; i < 3; i++) {
if ((splitcount[i][0] > 0) && (splitcount[i][1] > 0)) {
int midp = Math.abs(splitcount[i][0] - splitcount[i][1]);
if (midp < bestmidp) {
bestaxis = i;
bestmidp = midp;
}
}
}
if (bestaxis >= 0) {
//sets[0].reserve(splitcount[bestaxis][0]);
//sets[1].reserve(splitcount[bestaxis][1]);
split(leaves, sets[0], sets[1], org, axis[bestaxis]);
} else {
//sets[1].reserve(leaves.size()/2);
for (int i = 0, ni = leaves.size(); i < ni; i++) {
sets[i & 1].add(leaves.getQuick(i));
}
}
Node node = createnode(pdbvt, null, vol, null);
node.childs[0] = topdown(pdbvt, sets[0], bu_treshold);
node.childs[1] = topdown(pdbvt, sets[1], bu_treshold);
node.childs[0].parent = node;
node.childs[1].parent = node;
stack.leave();
return node;
} else {
bottomup(pdbvt, leaves);
return leaves.getQuick(0);
}
}
return leaves.getQuick(0);
}
use of com.bulletphysics.util.ObjectArrayList in project bdx by GoranM.
the class ShapeHull method buildHull.
public boolean buildHull(float margin) {
Stack stack = Stack.enter();
Vector3f norm = stack.allocVector3f();
int numSampleDirections = NUM_UNITSPHERE_POINTS;
{
int numPDA = shape.getNumPreferredPenetrationDirections();
if (numPDA != 0) {
for (int i = 0; i < numPDA; i++) {
shape.getPreferredPenetrationDirection(i, norm);
unitSpherePoints.getQuick(numSampleDirections).set(norm);
numSampleDirections++;
}
}
}
ObjectArrayList<Vector3f> supportPoints = new ObjectArrayList<Vector3f>();
MiscUtil.resize(supportPoints, NUM_UNITSPHERE_POINTS + ConvexShape.MAX_PREFERRED_PENETRATION_DIRECTIONS * 2, Suppliers.NEW_VECTOR3F_SUPPLIER);
for (int i = 0; i < numSampleDirections; i++) {
shape.localGetSupportingVertex(unitSpherePoints.getQuick(i), supportPoints.getQuick(i));
}
HullDesc hd = new HullDesc();
hd.flags = HullFlags.TRIANGLES;
hd.vcount = numSampleDirections;
//#ifdef BT_USE_DOUBLE_PRECISION
//hd.mVertices = &supportPoints[0];
//hd.mVertexStride = sizeof(btVector3);
//#else
hd.vertices = supportPoints;
//hd.vertexStride = 3 * 4;
//#endif
HullLibrary hl = new HullLibrary();
HullResult hr = new HullResult();
if (!hl.createConvexHull(hd, hr)) {
stack.leave();
return false;
}
MiscUtil.resize(vertices, hr.numOutputVertices, Suppliers.NEW_VECTOR3F_SUPPLIER);
for (int i = 0; i < hr.numOutputVertices; i++) {
vertices.getQuick(i).set(hr.outputVertices.getQuick(i));
}
numIndices = hr.numIndices;
MiscUtil.resize(indices, numIndices, 0);
for (int i = 0; i < numIndices; i++) {
indices.set(i, hr.indices.get(i));
}
// free temporary hull result that we just copied
hl.releaseResult(hr);
stack.leave();
return true;
}
Aggregations