Search in sources :

Example 11 with BoundingVolume

use of com.jme3.bounding.BoundingVolume in project jmonkeyengine by jMonkeyEngine.

the class UVCoordinatesGenerator method getBoundingSphere.

/**
     * This method returns the bounding sphere of the given geometries.
     * 
     * @param geometries
     *            the list of geometries
     * @return bounding sphere of the given geometries
     */
/* package */
static BoundingSphere getBoundingSphere(Geometry... geometries) {
    BoundingSphere result = null;
    for (Geometry geometry : geometries) {
        geometry.updateModelBound();
        BoundingVolume bv = geometry.getModelBound();
        if (bv instanceof BoundingBox) {
            BoundingBox bb = (BoundingBox) bv;
            float r = Math.max(bb.getXExtent(), bb.getYExtent());
            r = Math.max(r, bb.getZExtent());
            return new BoundingSphere(r, bb.getCenter());
        } else if (bv instanceof BoundingSphere) {
            return (BoundingSphere) bv;
        } else {
            throw new IllegalStateException("Unknown bounding volume type: " + bv.getClass().getName());
        }
    }
    return result;
}
Also used : Geometry(com.jme3.scene.Geometry) BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume)

Example 12 with BoundingVolume

use of com.jme3.bounding.BoundingVolume in project jmonkeyengine by jMonkeyEngine.

the class UVCoordinatesGenerator method getBoundingBox.

/**
     * This method returns the bounding box of the given geometries.
     * 
     * @param geometries
     *            the list of geometries
     * @return bounding box of the given geometries
     */
public static BoundingBox getBoundingBox(Geometry... geometries) {
    BoundingBox result = null;
    for (Geometry geometry : geometries) {
        geometry.updateModelBound();
        BoundingVolume bv = geometry.getModelBound();
        if (bv instanceof BoundingBox) {
            return (BoundingBox) bv;
        } else if (bv instanceof BoundingSphere) {
            BoundingSphere bs = (BoundingSphere) bv;
            float r = bs.getRadius();
            return new BoundingBox(bs.getCenter(), r, r, r);
        } else {
            throw new IllegalStateException("Unknown bounding volume type: " + bv.getClass().getName());
        }
    }
    return result;
}
Also used : Geometry(com.jme3.scene.Geometry) BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume)

Example 13 with BoundingVolume

use of com.jme3.bounding.BoundingVolume in project jmonkeyengine by jMonkeyEngine.

the class BoundingBox method transform.

/**
     * <code>transform</code> modifies the center of the box to reflect the
     * change made via a rotation, translation and scale.
     * 
     * @param trans 
     *            the transform to apply
     * @param store
     *            box to store result in
     */
public BoundingVolume transform(Transform trans, BoundingVolume store) {
    BoundingBox box;
    if (store == null || store.getType() != Type.AABB) {
        box = new BoundingBox();
    } else {
        box = (BoundingBox) store;
    }
    center.mult(trans.getScale(), box.center);
    trans.getRotation().mult(box.center, box.center);
    box.center.addLocal(trans.getTranslation());
    TempVars vars = TempVars.get();
    Matrix3f transMatrix = vars.tempMat3;
    transMatrix.set(trans.getRotation());
    // Make the rotation matrix all positive to get the maximum x/y/z extent
    transMatrix.absoluteLocal();
    Vector3f scale = trans.getScale();
    vars.vect1.set(xExtent * FastMath.abs(scale.x), yExtent * FastMath.abs(scale.y), zExtent * FastMath.abs(scale.z));
    transMatrix.mult(vars.vect1, vars.vect2);
    // Assign the biggest rotations after scales.
    box.xExtent = FastMath.abs(vars.vect2.getX());
    box.yExtent = FastMath.abs(vars.vect2.getY());
    box.zExtent = FastMath.abs(vars.vect2.getZ());
    vars.release();
    return box;
}
Also used : TempVars(com.jme3.util.TempVars)

Example 14 with BoundingVolume

use of com.jme3.bounding.BoundingVolume 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 15 with BoundingVolume

use of com.jme3.bounding.BoundingVolume 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)

Aggregations

BoundingVolume (com.jme3.bounding.BoundingVolume)18 BoundingBox (com.jme3.bounding.BoundingBox)10 TempVars (com.jme3.util.TempVars)10 BoundingSphere (com.jme3.bounding.BoundingSphere)7 Geometry (com.jme3.scene.Geometry)4 UnsupportedCollisionException (com.jme3.collision.UnsupportedCollisionException)3 Spatial (com.jme3.scene.Spatial)3 CollisionResult (com.jme3.collision.CollisionResult)2 CollisionResults (com.jme3.collision.CollisionResults)2 Vector3f (com.jme3.math.Vector3f)2 InputCapsule (com.jme3.export.InputCapsule)1 MatParamOverride (com.jme3.material.MatParamOverride)1 Matrix4f (com.jme3.math.Matrix4f)1 Camera (com.jme3.renderer.Camera)1 Bucket (com.jme3.renderer.queue.RenderQueue.Bucket)1 ShadowMode (com.jme3.renderer.queue.RenderQueue.ShadowMode)1 Node (com.jme3.scene.Node)1 BlenderFileException (com.jme3.scene.plugins.blender.file.BlenderFileException)1 FileBlockHeader (com.jme3.scene.plugins.blender.file.FileBlockHeader)1 Pointer (com.jme3.scene.plugins.blender.file.Pointer)1