Search in sources :

Example 1 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class Dbvt method update.

public boolean update(Node leaf, DbvtAabbMm volume, float margin) {
    if (leaf.volume.Contain(volume)) {
        return false;
    }
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    tmp.set(margin, margin, margin);
    volume.Expand(tmp);
    update(leaf, volume);
    stack.leave();
    return true;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 2 with Stack

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

Example 3 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class Dbvt method update.

public boolean update(Node leaf, DbvtAabbMm volume, Vector3f velocity, float margin) {
    if (leaf.volume.Contain(volume)) {
        return false;
    }
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    tmp.set(margin, margin, margin);
    volume.Expand(tmp);
    volume.SignedExpand(velocity);
    update(leaf, volume);
    stack.leave();
    return true;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 4 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class DbvtAabbMm method ProjectMinimum.

public float ProjectMinimum(Vector3f v, int signs) {
    Vector3f[] b = new Vector3f[] { mx, mi };
    Stack stack = Stack.enter();
    Vector3f p = stack.allocVector3f();
    p.set(b[(signs >> 0) & 1].x, b[(signs >> 1) & 1].y, b[(signs >> 2) & 1].z);
    float result = p.dot(v);
    stack.leave();
    return result;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Example 5 with Stack

use of com.bulletphysics.util.Stack in project bdx by GoranM.

the class DbvtAabbMm method FromCR.

public static DbvtAabbMm FromCR(Vector3f c, float r, DbvtAabbMm out) {
    Stack stack = Stack.enter();
    Vector3f tmp = stack.allocVector3f();
    tmp.set(r, r, r);
    DbvtAabbMm result = FromCE(c, tmp, out);
    stack.leave();
    return result;
}
Also used : Vector3f(javax.vecmath.Vector3f) Stack(com.bulletphysics.util.Stack)

Aggregations

Stack (com.bulletphysics.util.Stack)252 Vector3f (javax.vecmath.Vector3f)197 Transform (com.bulletphysics.linearmath.Transform)65 Matrix3f (javax.vecmath.Matrix3f)23 ManifoldPoint (com.bulletphysics.collision.narrowphase.ManifoldPoint)15 AABB (com.bulletphysics.extras.gimpact.BoxCollision.AABB)15 StaticAlloc (com.bulletphysics.util.StaticAlloc)12 CollisionObject (com.bulletphysics.collision.dispatch.CollisionObject)10 CollisionShape (com.bulletphysics.collision.shapes.CollisionShape)10 TypedConstraint (com.bulletphysics.dynamics.constraintsolver.TypedConstraint)10 Vector4f (javax.vecmath.Vector4f)8 CompoundShape (com.bulletphysics.collision.shapes.CompoundShape)6 ConcaveShape (com.bulletphysics.collision.shapes.ConcaveShape)5 SphereShape (com.bulletphysics.collision.shapes.SphereShape)5 RigidBody (com.bulletphysics.dynamics.RigidBody)5 Quat4f (javax.vecmath.Quat4f)5 ConvexShape (com.bulletphysics.collision.shapes.ConvexShape)4 ObjectArrayList (com.bulletphysics.util.ObjectArrayList)4 PersistentManifold (com.bulletphysics.collision.narrowphase.PersistentManifold)3 VoronoiSimplexSolver (com.bulletphysics.collision.narrowphase.VoronoiSimplexSolver)3