Ejemplo n.º 1
0
  // stackless refit
  protected void refit() {
    AABB leafbox = Stack.alloc(AABB.class);
    AABB bound = Stack.alloc(AABB.class);
    AABB temp_box = Stack.alloc(AABB.class);

    int nodecount = getNodeCount();
    while ((nodecount--) != 0) {
      if (isLeafNode(nodecount)) {
        primitive_manager.get_primitive_box(getNodeData(nodecount), leafbox);
        setNodeBound(nodecount, leafbox);
      } else {
        // const BT_BVH_TREE_NODE * nodepointer = get_node_pointer(nodecount);
        // get left bound
        bound.invalidate();

        int child_node = getLeftNode(nodecount);
        if (child_node != 0) {
          getNodeBound(child_node, temp_box);
          bound.merge(temp_box);
        }

        child_node = getRightNode(nodecount);
        if (child_node != 0) {
          getNodeBound(child_node, temp_box);
          bound.merge(temp_box);
        }

        setNodeBound(nodecount, bound);
      }
    }
  }
Ejemplo n.º 2
0
  private static boolean _node_collision(
      GImpactBvh boxset0,
      GImpactBvh boxset1,
      BoxBoxTransformCache trans_cache_1to0,
      int node0,
      int node1,
      boolean complete_primitive_tests) {
    AABB box0 = Stack.alloc(AABB.class);
    boxset0.getNodeBound(node0, box0);
    AABB box1 = Stack.alloc(AABB.class);
    boxset1.getNodeBound(node1, box1);

    return box0.overlapping_trans_cache(box1, trans_cache_1to0, complete_primitive_tests);
    // box1.appy_transform_trans_cache(trans_cache_1to0);
    // return box0.has_collision(box1);
  }
Ejemplo n.º 3
0
  /** Returns the indices of the primitives in the primitive_manager field. */
  public boolean rayQuery(Vector3f ray_dir, Vector3f ray_origin, IntArrayList collided_results) {
    int curIndex = 0;
    int numNodes = getNodeCount();

    AABB bound = Stack.alloc(AABB.class);

    while (curIndex < numNodes) {
      getNodeBound(curIndex, bound);

      // catch bugs in tree data

      boolean aabbOverlap = bound.collide_ray(ray_origin, ray_dir);
      boolean isleafnode = isLeafNode(curIndex);

      if (isleafnode && aabbOverlap) {
        collided_results.add(getNodeData(curIndex));
      }

      if (aabbOverlap || isleafnode) {
        // next subnode
        curIndex++;
      } else {
        // skip node
        curIndex += getEscapeNodeIndex(curIndex);
      }
    }
    if (collided_results.size() > 0) {
      return true;
    }
    return false;
  }
Ejemplo n.º 4
0
  /** This rebuild the entire set. */
  public void buildSet() {
    // obtain primitive boxes
    BvhDataArray primitive_boxes = new BvhDataArray();
    primitive_boxes.resize(primitive_manager.get_primitive_count());

    AABB tmpAABB = Stack.alloc(AABB.class);

    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);
  }
Ejemplo n.º 5
0
  public static void find_collision(
      GImpactBvh boxset0,
      Transform trans0,
      GImpactBvh boxset1,
      Transform trans1,
      PairSet collision_pairs) {
    if (boxset0.getNodeCount() == 0 || boxset1.getNodeCount() == 0) {
      return;
    }
    BoxBoxTransformCache trans_cache_1to0 = Stack.alloc(BoxBoxTransformCache.class);

    trans_cache_1to0.calc_from_homogenic(trans0, trans1);

    // #ifdef TRI_COLLISION_PROFILING
    // bt_begin_gim02_tree_time();
    // #endif //TRI_COLLISION_PROFILING

    _find_collision_pairs_recursive(
        boxset0, boxset1, collision_pairs, trans_cache_1to0, 0, 0, true);

    // #ifdef TRI_COLLISION_PROFILING
    // bt_end_gim02_tree_time();
    // #endif //TRI_COLLISION_PROFILING
  }
Ejemplo n.º 6
0
 /** Returns the indices of the primitives in the primitive_manager field. */
 public boolean boxQueryTrans(AABB box, Transform transform, IntArrayList collided_results) {
   AABB transbox = Stack.alloc(box);
   transbox.appy_transform(transform);
   return boxQuery(transbox, collided_results);
 }