use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.
the class Dbvt method bottomup.
private static void bottomup(Dbvt pdbvt, ObjectArrayList<Node> leaves) {
DbvtAabbMm tmpVolume = new DbvtAabbMm();
while (leaves.size() > 1) {
float minsize = BulletGlobals.SIMD_INFINITY;
int[] minidx = new int[] { -1, -1 };
for (int i = 0; i < leaves.size(); i++) {
for (int j = i + 1; j < leaves.size(); j++) {
float sz = size(merge(leaves.getQuick(i).volume, leaves.getQuick(j).volume, tmpVolume));
if (sz < minsize) {
minsize = sz;
minidx[0] = i;
minidx[1] = j;
}
}
}
Node[] n = new Node[] { leaves.getQuick(minidx[0]), leaves.getQuick(minidx[1]) };
Node p = createnode(pdbvt, null, merge(n[0].volume, n[1].volume, new DbvtAabbMm()), null);
p.childs[0] = n[0];
p.childs[1] = n[1];
n[0].parent = p;
n[1].parent = p;
// JAVA NOTE: check
leaves.setQuick(minidx[0], p);
Collections.swap(leaves, minidx[1], leaves.size() - 1);
leaves.removeQuick(leaves.size() - 1);
}
}
use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.
the class Dbvt method sort.
private static Node sort(Node n, Node[] r) {
Node p = n.parent;
assert (n.isinternal());
// JAVA TODO: fix this
if (p != null && p.hashCode() > n.hashCode()) {
int i = indexof(n);
int j = 1 - i;
Node s = p.childs[j];
Node q = p.parent;
assert (n == p.childs[i]);
if (q != null) {
q.childs[indexof(p)] = n;
} else {
r[0] = n;
}
s.parent = n;
p.parent = n;
n.parent = q;
p.childs[0] = n.childs[0];
p.childs[1] = n.childs[1];
n.childs[0].parent = p;
n.childs[1].parent = p;
n.childs[i] = p;
n.childs[j] = s;
DbvtAabbMm.swap(p.volume, n.volume);
return p;
}
return n;
}
use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.
the class Dbvt method update.
public void update(Node leaf, DbvtAabbMm volume) {
Node root = removeleaf(this, leaf);
if (root != null) {
if (lkhd >= 0) {
for (int i = 0; (i < lkhd) && root.parent != null; i++) {
root = root.parent;
}
} else {
root = this.root;
}
}
leaf.volume.set(volume);
insertleaf(this, root, leaf);
}
use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.
the class Dbvt method collideRAY.
public static void collideRAY(Node root, Vector3f origin, Vector3f direction, ICollide policy) {
//DBVT_CHECKTYPE
if (root != null) {
Stack st = Stack.enter();
Vector3f normal = st.allocVector3f();
normal.normalize(direction);
Vector3f invdir = st.allocVector3f();
invdir.set(1f / normal.x, 1f / normal.y, 1f / normal.z);
int[] signs = new int[] { direction.x < 0 ? 1 : 0, direction.y < 0 ? 1 : 0, direction.z < 0 ? 1 : 0 };
ObjectArrayList<Node> stack = new ObjectArrayList<Node>(SIMPLE_STACKSIZE);
stack.add(root);
do {
Node node = stack.remove(stack.size() - 1);
if (DbvtAabbMm.Intersect(node.volume, origin, invdir, signs)) {
if (node.isinternal()) {
stack.add(node.childs[0]);
stack.add(node.childs[1]);
} else {
policy.Process(node);
}
}
} while (stack.size() != 0);
st.leave();
}
}
Aggregations