Search in sources :

Example 1 with UnsupportedCollisionException

use of com.jme3.collision.UnsupportedCollisionException in project jmonkeyengine by jMonkeyEngine.

the class BoundingSphere method collideWith.

public int collideWith(Collidable other, CollisionResults results) {
    if (other instanceof Ray) {
        Ray ray = (Ray) other;
        return collideWithRay(ray, results);
    } else if (other instanceof Triangle) {
        Triangle t = (Triangle) other;
        return collideWithTri(t, results);
    } else if (other instanceof BoundingVolume) {
        if (intersects((BoundingVolume) other)) {
            CollisionResult result = new CollisionResult();
            results.addCollision(result);
            return 1;
        }
        return 0;
    } else if (other instanceof Spatial) {
        return ((Spatial) other).collideWith(this, results);
    } else {
        throw new UnsupportedCollisionException();
    }
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) Spatial(com.jme3.scene.Spatial) UnsupportedCollisionException(com.jme3.collision.UnsupportedCollisionException)

Example 2 with UnsupportedCollisionException

use of com.jme3.collision.UnsupportedCollisionException in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method collideWith.

@Override
public int collideWith(Collidable other, CollisionResults results) {
    if (other instanceof Ray) {
        Ray ray = (Ray) other;
        return collideWithRay(ray, results);
    } else if (other instanceof Triangle) {
        Triangle t = (Triangle) other;
        if (intersects(t.get1(), t.get2(), t.get3())) {
            CollisionResult r = new CollisionResult();
            results.addCollision(r);
            return 1;
        }
        return 0;
    } else if (other instanceof BoundingVolume) {
        if (intersects((BoundingVolume) other)) {
            CollisionResult r = new CollisionResult();
            results.addCollision(r);
            return 1;
        }
        return 0;
    } else if (other instanceof Spatial) {
        return ((Spatial) other).collideWith(this, results);
    } else {
        throw new UnsupportedCollisionException("With: " + other.getClass().getSimpleName());
    }
}
Also used : CollisionResult(com.jme3.collision.CollisionResult) Spatial(com.jme3.scene.Spatial) UnsupportedCollisionException(com.jme3.collision.UnsupportedCollisionException)

Example 3 with UnsupportedCollisionException

use of com.jme3.collision.UnsupportedCollisionException in project jmonkeyengine by jMonkeyEngine.

the class BIHTree method collideWithBoundingVolume.

private int collideWithBoundingVolume(BoundingVolume bv, Matrix4f worldMatrix, CollisionResults results) {
    BoundingBox bbox;
    if (bv instanceof BoundingSphere) {
        BoundingSphere sphere = (BoundingSphere) bv;
        bbox = new BoundingBox(bv.getCenter().clone(), sphere.getRadius(), sphere.getRadius(), sphere.getRadius());
    } else if (bv instanceof BoundingBox) {
        bbox = new BoundingBox((BoundingBox) bv);
    } else {
        throw new UnsupportedCollisionException("BoundingVolume:" + bv);
    }
    bbox.transform(worldMatrix.invert(), bbox);
    return root.intersectWhere(bv, bbox, worldMatrix, this, results);
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) UnsupportedCollisionException(com.jme3.collision.UnsupportedCollisionException)

Aggregations

UnsupportedCollisionException (com.jme3.collision.UnsupportedCollisionException)3 CollisionResult (com.jme3.collision.CollisionResult)2 Spatial (com.jme3.scene.Spatial)2 BoundingBox (com.jme3.bounding.BoundingBox)1 BoundingSphere (com.jme3.bounding.BoundingSphere)1