use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.
the class Dbvt method update.
public void update(Node leaf, int lookahead) {
Node root = removeleaf(this, leaf);
if (root != null) {
if (lookahead >= 0) {
for (int i = 0; (i < lookahead) && root.parent != null; i++) {
root = root.parent;
}
} else {
root = this.root;
}
}
insertleaf(this, root, leaf);
}
use of com.bulletphysics.collision.broadphase.Dbvt.Node 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.collision.broadphase.Dbvt.Node 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.collision.broadphase.Dbvt.Node in project bdx by GoranM.
the class Dbvt method optimizeIncremental.
public void optimizeIncremental(int passes) {
if (passes < 0) {
passes = leaves;
}
if (root != null && (passes > 0)) {
Node[] root_ref = new Node[1];
do {
Node node = root;
int bit = 0;
while (node.isinternal()) {
root_ref[0] = root;
node = sort(node, root_ref).childs[(opath >>> bit) & 1];
root = root_ref[0];
bit = (bit + 1) & (/*sizeof(unsigned)*/
4 * 8 - 1);
}
update(node);
++opath;
} while ((--passes) != 0);
}
}
use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.
the class Dbvt method createnode.
private static Node createnode(Dbvt pdbvt, Node parent, DbvtAabbMm volume, Object data) {
Node node;
if (pdbvt.free != null) {
node = pdbvt.free;
pdbvt.free = null;
} else {
node = new Node();
}
node.parent = parent;
node.volume.set(volume);
node.data = data;
node.childs[1] = null;
return node;
}
Aggregations