use of spacegraph.space3d.phys.util.OArrayList in project narchy by automenta.
the class Dbvt method collideRAY.
public static void collideRAY(Node root, v3 origin, v3 direction, ICollide policy) {
// DBVT_CHECKTYPE
if (root != null) {
v3 normal = new v3();
normal.normalize(direction);
v3 invdir = new v3();
invdir.set(1f / normal.x, 1f / normal.y, 1f / normal.z);
int[] signs = { direction.x < 0 ? 1 : 0, direction.y < 0 ? 1 : 0, direction.z < 0 ? 1 : 0 };
OArrayList<Node> stack = new OArrayList<>(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.isEmpty());
}
}
use of spacegraph.space3d.phys.util.OArrayList in project narchy by automenta.
the class Dbvt method collideOCL.
public static void collideOCL(Node root, v3[] normals, float[] offsets, v3 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;
OArrayList<sStkNPS> stock = new OArrayList<>();
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);
// return array[index];
sStkNPS se = stock.get(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 (ICollide.Descent(se.node)) {
if (se.node.isinternal()) {
Node[] pns = { se.node.childs[0], se.node.childs[1] };
sStkNPS[] nes = { 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);
}
}
Aggregations