Search in sources :

Example 1 with AABB

use of com.bulletphysics.extras.gimpact.BoxCollision.AABB in project bdx by GoranM.

the class BvhTree method _build_sub_tree.

protected void _build_sub_tree(BvhDataArray primitive_boxes, int startIndex, int endIndex) {
    int curIndex = num_nodes;
    num_nodes++;
    assert ((endIndex - startIndex) > 0);
    if ((endIndex - startIndex) == 1) {
        // We have a leaf node
        //setNodeBound(curIndex,primitive_boxes[startIndex].m_bound);
        //m_node_array[curIndex].setDataIndex(primitive_boxes[startIndex].m_data);
        node_array.set(curIndex, primitive_boxes, startIndex);
        return;
    }
    // calculate Best Splitting Axis and where to split it. Sort the incoming 'leafNodes' array within range 'startIndex/endIndex'.
    // split axis
    int splitIndex = _calc_splitting_axis(primitive_boxes, startIndex, endIndex);
    splitIndex = _sort_and_calc_splitting_index(primitive_boxes, startIndex, endIndex, splitIndex);
    //calc this node bounding box
    Stack stack = Stack.enter();
    AABB node_bound = stack.allocAABB();
    AABB tmpAABB = stack.allocAABB();
    node_bound.invalidate();
    for (int i = startIndex; i < endIndex; i++) {
        primitive_boxes.getBound(i, tmpAABB);
        node_bound.merge(tmpAABB);
    }
    setNodeBound(curIndex, node_bound);
    // build left branch
    _build_sub_tree(primitive_boxes, startIndex, splitIndex);
    // build right branch
    _build_sub_tree(primitive_boxes, splitIndex, endIndex);
    node_array.setEscapeIndex(curIndex, num_nodes - curIndex);
    stack.leave();
}
Also used : AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Example 2 with AABB

use of com.bulletphysics.extras.gimpact.BoxCollision.AABB in project bdx by GoranM.

the class GImpactBvh method _node_collision.

private static boolean _node_collision(GImpactBvh boxset0, GImpactBvh boxset1, BoxBoxTransformCache trans_cache_1to0, int node0, int node1, boolean complete_primitive_tests) {
    Stack stack = Stack.enter();
    AABB box0 = stack.allocAABB();
    boxset0.getNodeBound(node0, box0);
    AABB box1 = stack.allocAABB();
    boxset1.getNodeBound(node1, box1);
    boolean result = box0.overlapping_trans_cache(box1, trans_cache_1to0, complete_primitive_tests);
    //box1.appy_transform_trans_cache(trans_cache_1to0);
    //return box0.has_collision(box1);
    stack.leave();
    return result;
}
Also used : AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Example 3 with AABB

use of com.bulletphysics.extras.gimpact.BoxCollision.AABB in project bdx by GoranM.

the class GImpactBvh method buildSet.

/**
	 * This rebuild the entire set.
	 */
public void buildSet() {
    // obtain primitive boxes
    BvhDataArray primitive_boxes = new BvhDataArray();
    primitive_boxes.resize(primitive_manager.get_primitive_count());
    Stack stack = Stack.enter();
    AABB tmpAABB = stack.allocAABB();
    for (int i = 0; i < primitive_boxes.size(); i++) {
        //primitive_manager.get_primitive_box(i,primitive_boxes[i].bound);
        primitive_manager.get_primitive_box(i, tmpAABB);
        primitive_boxes.setBound(i, tmpAABB);
        primitive_boxes.setData(i, i);
    }
    box_tree.build_tree(primitive_boxes);
    stack.leave();
}
Also used : AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Example 4 with AABB

use of com.bulletphysics.extras.gimpact.BoxCollision.AABB in project bdx by GoranM.

the class GImpactCollisionAlgorithm method gimpacttrimeshpart_vs_plane_collision.

protected void gimpacttrimeshpart_vs_plane_collision(CollisionObject body0, CollisionObject body1, GImpactMeshShapePart shape0, StaticPlaneShape shape1, boolean swapped) {
    Stack stack = Stack.enter();
    Transform orgtrans0 = body0.getWorldTransform(stack.allocTransform());
    Transform orgtrans1 = body1.getWorldTransform(stack.allocTransform());
    StaticPlaneShape planeshape = shape1;
    Vector4f plane = stack.allocVector4f();
    PlaneShape.get_plane_equation_transformed(planeshape, orgtrans1, plane);
    // test box against plane
    AABB tribox = stack.allocAABB();
    shape0.getAabb(orgtrans0, tribox.min, tribox.max);
    tribox.increment_margin(planeshape.getMargin());
    if (tribox.plane_classify(plane) != PlaneIntersectionType.COLLIDE_PLANE) {
        return;
    }
    shape0.lockChildShapes();
    float margin = shape0.getMargin() + planeshape.getMargin();
    Vector3f vertex = stack.allocVector3f();
    Vector3f tmp = stack.allocVector3f();
    int vi = shape0.getVertexCount();
    while ((vi--) != 0) {
        shape0.getVertex(vi, vertex);
        orgtrans0.transform(vertex);
        float distance = VectorUtil.dot3(vertex, plane) - plane.w - margin;
        if (//add contact
        distance < 0f) {
            if (swapped) {
                tmp.set(-plane.x, -plane.y, -plane.z);
                addContactPoint(body1, body0, vertex, tmp, distance);
            } else {
                tmp.set(plane.x, plane.y, plane.z);
                addContactPoint(body0, body1, vertex, tmp, distance);
            }
        }
    }
    shape0.unlockChildShapes();
    stack.leave();
}
Also used : Vector4f(javax.vecmath.Vector4f) Vector3f(javax.vecmath.Vector3f) StaticPlaneShape(com.bulletphysics.collision.shapes.StaticPlaneShape) Transform(com.bulletphysics.linearmath.Transform) AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Example 5 with AABB

use of com.bulletphysics.extras.gimpact.BoxCollision.AABB in project bdx by GoranM.

the class GImpactCollisionAlgorithm method gimpact_vs_gimpact_find_pairs.

void gimpact_vs_gimpact_find_pairs(Transform trans0, Transform trans1, GImpactShapeInterface shape0, GImpactShapeInterface shape1, PairSet pairset) {
    if (shape0.hasBoxSet() && shape1.hasBoxSet()) {
        GImpactBvh.find_collision(shape0.getBoxSet(), trans0, shape1.getBoxSet(), trans1, pairset);
    } else {
        Stack stack = Stack.enter();
        AABB boxshape0 = stack.allocAABB();
        AABB boxshape1 = stack.allocAABB();
        int i = shape0.getNumChildShapes();
        while ((i--) != 0) {
            shape0.getChildAabb(i, trans0, boxshape0.min, boxshape0.max);
            int j = shape1.getNumChildShapes();
            while ((j--) != 0) {
                shape1.getChildAabb(i, trans1, boxshape1.min, boxshape1.max);
                if (boxshape1.has_collision(boxshape0)) {
                    pairset.push_pair(i, j);
                }
            }
        }
        stack.leave();
    }
}
Also used : AABB(com.bulletphysics.extras.gimpact.BoxCollision.AABB) Stack(com.bulletphysics.util.Stack)

Aggregations

AABB (com.bulletphysics.extras.gimpact.BoxCollision.AABB)17 Stack (com.bulletphysics.util.Stack)15 Transform (com.bulletphysics.linearmath.Transform)2 Vector3f (javax.vecmath.Vector3f)2 StaticPlaneShape (com.bulletphysics.collision.shapes.StaticPlaneShape)1 Vector4f (javax.vecmath.Vector4f)1