Search in sources :

Example 1 with Node

use of com.bulletphysics.collision.broadphase.Dbvt.Node 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);
    }
}
Also used : ObjectArrayList(com.bulletphysics.util.ObjectArrayList) Node(com.bulletphysics.collision.broadphase.Dbvt.Node) IntArrayList(com.bulletphysics.util.IntArrayList)

Example 2 with Node

use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.

the class Dbvt method insertleaf.

private static void insertleaf(Dbvt pdbvt, Node root, Node leaf) {
    if (pdbvt.root == null) {
        pdbvt.root = leaf;
        leaf.parent = null;
    } else {
        if (!root.isleaf()) {
            do {
                if (DbvtAabbMm.Proximity(root.childs[0].volume, leaf.volume) < DbvtAabbMm.Proximity(root.childs[1].volume, leaf.volume)) {
                    root = root.childs[0];
                } else {
                    root = root.childs[1];
                }
            } while (!root.isleaf());
        }
        Node prev = root.parent;
        Node node = createnode(pdbvt, prev, merge(leaf.volume, root.volume, new DbvtAabbMm()), null);
        if (prev != null) {
            prev.childs[indexof(root)] = node;
            node.childs[0] = root;
            root.parent = node;
            node.childs[1] = leaf;
            leaf.parent = node;
            do {
                if (!prev.volume.Contain(node.volume)) {
                    DbvtAabbMm.Merge(prev.childs[0].volume, prev.childs[1].volume, prev.volume);
                } else {
                    break;
                }
                node = prev;
            } while (null != (prev = node.parent));
        } else {
            node.childs[0] = root;
            root.parent = node;
            node.childs[1] = leaf;
            leaf.parent = node;
            pdbvt.root = node;
        }
    }
}
Also used : Node(com.bulletphysics.collision.broadphase.Dbvt.Node)

Example 3 with Node

use of com.bulletphysics.collision.broadphase.Dbvt.Node 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);
    }
}
Also used : ObjectArrayList(com.bulletphysics.util.ObjectArrayList) Node(com.bulletphysics.collision.broadphase.Dbvt.Node)

Example 4 with Node

use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.

the class Dbvt method insert.

public Node insert(DbvtAabbMm box, Object data) {
    Node leaf = createnode(this, null, box, data);
    insertleaf(this, root, leaf);
    leaves++;
    return leaf;
}
Also used : Node(com.bulletphysics.collision.broadphase.Dbvt.Node)

Example 5 with Node

use of com.bulletphysics.collision.broadphase.Dbvt.Node in project bdx by GoranM.

the class Dbvt method removeleaf.

private static Node removeleaf(Dbvt pdbvt, Node leaf) {
    if (leaf == pdbvt.root) {
        pdbvt.root = null;
        return null;
    } else {
        Node parent = leaf.parent;
        Node prev = parent.parent;
        Node sibling = parent.childs[1 - indexof(leaf)];
        if (prev != null) {
            prev.childs[indexof(parent)] = sibling;
            sibling.parent = prev;
            deletenode(pdbvt, parent);
            while (prev != null) {
                DbvtAabbMm pb = prev.volume;
                DbvtAabbMm.Merge(prev.childs[0].volume, prev.childs[1].volume, prev.volume);
                if (DbvtAabbMm.NotEqual(pb, prev.volume)) {
                    prev = prev.parent;
                } else {
                    break;
                }
            }
            return (prev != null ? prev : pdbvt.root);
        } else {
            pdbvt.root = sibling;
            sibling.parent = null;
            deletenode(pdbvt, parent);
            return pdbvt.root;
        }
    }
}
Also used : Node(com.bulletphysics.collision.broadphase.Dbvt.Node)

Aggregations

Node (com.bulletphysics.collision.broadphase.Dbvt.Node)14 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)5 Stack (com.bulletphysics.util.Stack)2 Vector3f (javax.vecmath.Vector3f)2 IntArrayList (com.bulletphysics.util.IntArrayList)1