Java Code Examples for com.jme3.bounding.BoundingBox#intersects()

The following examples show how to use com.jme3.bounding.BoundingBox#intersects() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TerrainQuad.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Find what terrain patches need normal recalculations and update
 * their normals;
 */
protected void fixNormals(BoundingBox affectedArea) {
    if (children == null)
        return;

    // go through the children and see if they collide with the affectedAreaBBox
    // if they do, then update their normals
    for (int x = children.size(); --x >= 0;) {
        Spatial child = children.get(x);
        if (child instanceof TerrainQuad) {
            if (affectedArea != null && affectedArea.intersects( child.getWorldBound()) )
                ((TerrainQuad) child).fixNormals(affectedArea);
        } else if (child instanceof TerrainPatch) {
            if (affectedArea != null && affectedArea.intersects(child.getWorldBound()) )
                ((TerrainPatch) child).updateNormals(); // recalculate the patch's normals
        }
    }
}
 
Example 2
Source File: TerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Find what terrain patches need normal recalculations and update
 * their normals;
 */
protected void fixNormals(BoundingBox affectedArea) {
    if (children == null)
        return;

    // go through the children and see if they collide with the affectedAreaBBox
    // if they do, then update their normals
    for (int x = children.size(); --x >= 0;) {
        Spatial child = children.get(x);
        if (child instanceof TerrainQuad) {
            if (affectedArea != null && affectedArea.intersects(((TerrainQuad) child).getWorldBound()) )
                ((TerrainQuad) child).fixNormals(affectedArea);
        } else if (child instanceof TerrainPatch) {
            if (affectedArea != null && affectedArea.intersects(((TerrainPatch) child).getWorldBound()) )
                ((TerrainPatch) child).updateNormals(); // recalculate the patch's normals
        }
    }
}
 
Example 3
Source File: TerrainQuad.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * fix the normals on the edge of the terrain patches.
 */
protected void fixNormalEdges(BoundingBox affectedArea) {
    if (children == null)
        return;

    for (int x = children.size(); --x >= 0;) {
        Spatial child = children.get(x);
        if (child instanceof TerrainQuad) {
            if (affectedArea != null && affectedArea.intersects(child.getWorldBound()) )
                ((TerrainQuad) child).fixNormalEdges(affectedArea);
        } else if (child instanceof TerrainPatch) {
            if (affectedArea != null && !affectedArea.intersects(child.getWorldBound()) ) // if doesn't intersect, continue
                continue;

            TerrainPatch tp = (TerrainPatch) child;
            TerrainPatch right = findRightPatch(tp);
            TerrainPatch bottom = findDownPatch(tp);
            TerrainPatch top = findTopPatch(tp);
            TerrainPatch left = findLeftPatch(tp);
            TerrainPatch topLeft = null;
            if (top != null)
                topLeft = findLeftPatch(top);
            TerrainPatch bottomRight = null;
            if (right != null)
                bottomRight = findDownPatch(right);
            TerrainPatch topRight = null;
            if (top != null)
                topRight = findRightPatch(top);
            TerrainPatch bottomLeft = null;
            if (left != null)
                bottomLeft = findDownPatch(left);

            tp.fixNormalEdges(right, bottom, top, left, bottomRight, bottomLeft, topRight, topLeft);

        }
    } // for each child

}
 
Example 4
Source File: TerrainQuad.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * fix the normals on the edge of the terrain patches.
 */
protected void fixNormalEdges(BoundingBox affectedArea) {
    if (children == null)
        return;

    for (int x = children.size(); --x >= 0;) {
        Spatial child = children.get(x);
        if (child instanceof TerrainQuad) {
            if (affectedArea != null && affectedArea.intersects(((TerrainQuad) child).getWorldBound()) )
                ((TerrainQuad) child).fixNormalEdges(affectedArea);
        } else if (child instanceof TerrainPatch) {
            if (affectedArea != null && !affectedArea.intersects(((TerrainPatch) child).getWorldBound()) ) // if doesn't intersect, continue
                continue;

            TerrainPatch tp = (TerrainPatch) child;
            TerrainPatch right = findRightPatch(tp);
            TerrainPatch bottom = findDownPatch(tp);
            TerrainPatch top = findTopPatch(tp);
            TerrainPatch left = findLeftPatch(tp);
            TerrainPatch topLeft = null;
            if (top != null)
                topLeft = findLeftPatch(top);
            TerrainPatch bottomRight = null;
            if (right != null)
                bottomRight = findDownPatch(right);
            TerrainPatch topRight = null;
            if (top != null)
                topRight = findRightPatch(top);
            TerrainPatch bottomLeft = null;
            if (left != null)
                bottomLeft = findDownPatch(left);

            tp.fixNormalEdges(right, bottom, top, left, bottomRight, bottomLeft, topRight, topLeft);

        }
    } // for each child

}
 
Example 5
Source File: Octnode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private float getAdditionCost(BoundingBox bbox, OCTTriangle t){
    if (bbox.intersects(t.get1(), t.get2(), t.get3())){
        float d1 = bbox.distanceToEdge(t.get1());
        float d2 = bbox.distanceToEdge(t.get2());
        float d3 = bbox.distanceToEdge(t.get3());
        return d1 + d2 + d3;
    }
    return Float.POSITIVE_INFINITY;
}