Java Code Examples for com.jme3.math.Ray#intersects()

The following examples show how to use com.jme3.math.Ray#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: Octnode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public final void intersectWhere(Ray r, Geometry[] geoms, float sceneMin, float sceneMax,
                                        CollisionResults results){
    for (OCTTriangle t : tris){
        float d = r.intersects(t.get1(), t.get2(), t.get3());
        if (Float.isInfinite(d))
            continue;

        Vector3f contactPoint = new Vector3f(r.getDirection()).multLocal(d).addLocal(r.getOrigin());
        CollisionResult result = new CollisionResult(geoms[t.getGeometryIndex()],
                                                     contactPoint,
                                                     d,
                                                     t.getTriangleIndex());
        results.addCollision(result);
    }
    for (int i = 0; i < 8; i++){
        Octnode child = children[i];
        if (child == null)
            continue;

        if (child.bbox.intersects(r)){
            child.intersectWhere(r, geoms, sceneMin, sceneMax, results);
        }
    }
}
 
Example 2
Source File: BIHNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public final int intersectBrute(Ray r,
        Matrix4f worldMatrix,
        BIHTree tree,
        float sceneMin,
        float sceneMax,
        CollisionResults results) {
    float tHit = Float.POSITIVE_INFINITY;
    
    TempVars vars = TempVars.get();

    Vector3f v1 = vars.vect1,
            v2 = vars.vect2,
            v3 = vars.vect3;

    int cols = 0;

    ArrayList<BIHStackData> stack = vars.bihStack;
    stack.clear();
    stack.add(new BIHStackData(this, 0, 0));
    stackloop:
    while (stack.size() > 0) {

        BIHStackData data = stack.remove(stack.size() - 1);
        BIHNode node = data.node;

        leafloop:
        while (node.axis != 3) { // while node is not a leaf
            BIHNode nearNode, farNode;
            nearNode = node.left;
            farNode = node.right;

            stack.add(new BIHStackData(farNode, 0, 0));
            node = nearNode;
        }

        // a leaf
        for (int i = node.leftIndex; i <= node.rightIndex; i++) {
            tree.getTriangle(i, v1, v2, v3);

            if (worldMatrix != null) {
                worldMatrix.mult(v1, v1);
                worldMatrix.mult(v2, v2);
                worldMatrix.mult(v3, v3);
            }

            float t = r.intersects(v1, v2, v3);
            if (t < tHit) {
                tHit = t;
                Vector3f contactPoint = new Vector3f(r.direction).multLocal(tHit).addLocal(r.origin);
                CollisionResult cr = new CollisionResult(contactPoint, tHit);
                cr.setTriangleIndex(tree.getTriangleIndex(i));
                results.addCollision(cr);
                cols++;
            }
        }
    }
    vars.release();
    return cols;
}
 
Example 3
Source File: BIHNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public final int intersectBrute(Ray r,
        Matrix4f worldMatrix,
        BIHTree tree,
        float sceneMin,
        float sceneMax,
        CollisionResults results) {
    float tHit = Float.POSITIVE_INFINITY;
    
    TempVars vars = TempVars.get();

    Vector3f v1 = vars.vect1,
            v2 = vars.vect2,
            v3 = vars.vect3;

    int cols = 0;

    ArrayList<BIHStackData> stack = vars.bihStack;
    stack.clear();
    stack.add(new BIHStackData(this, 0, 0));
    stackloop:
    while (stack.size() > 0) {

        BIHStackData data = stack.remove(stack.size() - 1);
        BIHNode node = data.node;

        leafloop:
        while (node.axis != 3) { // while node is not a leaf
            BIHNode nearNode, farNode;
            nearNode = node.left;
            farNode = node.right;

            stack.add(new BIHStackData(farNode, 0, 0));
            node = nearNode;
        }

        // a leaf
        for (int i = node.leftIndex; i <= node.rightIndex; i++) {
            tree.getTriangle(i, v1, v2, v3);

            if (worldMatrix != null) {
                worldMatrix.mult(v1, v1);
                worldMatrix.mult(v2, v2);
                worldMatrix.mult(v3, v3);
            }

            float t = r.intersects(v1, v2, v3);
            if (t < tHit) {
                tHit = t;
                Vector3f contactPoint = new Vector3f(r.direction).multLocal(tHit).addLocal(r.origin);
                CollisionResult cr = new CollisionResult(contactPoint, tHit);
                cr.setTriangleIndex(tree.getTriangleIndex(i));
                results.addCollision(cr);
                cols++;
            }
        }
    }
    vars.release();
    return cols;
}