Java Code Examples for com.jme3.bounding.BoundingVolume#collideWith()

The following examples show how to use com.jme3.bounding.BoundingVolume#collideWith() . 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: Ray.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public int collideWith(Collidable other, CollisionResults results) {
    if (other instanceof BoundingVolume) {
        BoundingVolume bv = (BoundingVolume) other;
        return bv.collideWith(this, results);
    } else if (other instanceof AbstractTriangle) {
        AbstractTriangle tri = (AbstractTriangle) other;
        float d = intersects(tri.get1(), tri.get2(), tri.get3());
        if (Float.isInfinite(d) || Float.isNaN(d)) {
            return 0;
        }

        Vector3f point = new Vector3f(direction).multLocal(d).addLocal(origin);
        results.addCollision(new CollisionResult(point, d));
        return 1;
    } else {
        throw new UnsupportedCollisionException();
    }
}
 
Example 2
Source File: Ray.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public int collideWith(Collidable other, CollisionResults results) {
    if (other instanceof BoundingVolume) {
        BoundingVolume bv = (BoundingVolume) other;
        return bv.collideWith(this, results);
    } else if (other instanceof AbstractTriangle) {
        AbstractTriangle tri = (AbstractTriangle) other;
        float d = intersects(tri.get1(), tri.get2(), tri.get3());
        if (Float.isInfinite(d) || Float.isNaN(d)) {
            return 0;
        }

        Vector3f point = new Vector3f(direction).multLocal(d).addLocal(origin);
        results.addCollision(new CollisionResult(point, d));
        return 1;
    } else {
        throw new UnsupportedCollisionException();
    }
}
 
Example 3
Source File: BIHTree.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private int collideWithRay(Ray r,
        Matrix4f worldMatrix,
        BoundingVolume worldBound,
        CollisionResults results) {

    TempVars vars = TempVars.get();
    try {
        CollisionResults boundResults = vars.collisionResults;
        boundResults.clear();
        worldBound.collideWith(r, boundResults);
        if (boundResults.size() > 0) {
            float tMin = boundResults.getClosestCollision().getDistance();
            float tMax = boundResults.getFarthestCollision().getDistance();

            if (tMax <= 0) {
                tMax = Float.POSITIVE_INFINITY;
            } else if (tMin == tMax) {
                tMin = 0;
            }

            if (tMin <= 0) {
                tMin = 0;
            }

            if (r.getLimit() < Float.POSITIVE_INFINITY) {
                tMax = Math.min(tMax, r.getLimit());
                if (tMin > tMax){
                    return 0;
                }
            }

//            return root.intersectBrute(r, worldMatrix, this, tMin, tMax, results);
            return root.intersectWhere(r, worldMatrix, this, tMin, tMax, results);
        }
        return 0;
    } finally {
        vars.release();
    }
}
 
Example 4
Source File: BIHTree.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private int collideWithRay(Ray r,
            Matrix4f worldMatrix,
            BoundingVolume worldBound,
            CollisionResults results) {

        boundResults.clear();
        worldBound.collideWith(r, boundResults);
        if (boundResults.size() > 0) {
            float tMin = boundResults.getClosestCollision().getDistance();
            float tMax = boundResults.getFarthestCollision().getDistance();

            if (tMax <= 0) {
                tMax = Float.POSITIVE_INFINITY;
            } else if (tMin == tMax) {
                tMin = 0;
            }

            if (tMin <= 0) {
                tMin = 0;
            }

            if (r.getLimit() < Float.POSITIVE_INFINITY) {
                tMax = Math.min(tMax, r.getLimit());
            }

//            return root.intersectBrute(r, worldMatrix, this, tMin, tMax, results);
            return root.intersectWhere(r, worldMatrix, this, tMin, tMax, results);
        }
        return 0;
    }