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

The following examples show how to use com.jme3.bounding.BoundingBox#getMax() . 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: BIHTree.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setMinMax(BoundingBox bbox, boolean doMin, int axis, float value) {
    Vector3f min = bbox.getMin(null);
    Vector3f max = bbox.getMax(null);

    if (doMin) {
        min.set(axis, value);
    } else {
        max.set(axis, value);
    }

    bbox.setMinMax(min, max);
}
 
Example 2
Source File: ParticleEmitter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Instantly emits available particles, up to num.
 */
public void emitParticles(int num) {
    // Force world transform to update
    this.getWorldTransform();

    TempVars vars = TempVars.get();

    BoundingBox bbox = (BoundingBox) this.getMesh().getBound();

    Vector3f min = vars.vect1;
    Vector3f max = vars.vect2;

    bbox.getMin(min);
    bbox.getMax(max);

    if (!Vector3f.isValidVector(min)) {
        min.set(Vector3f.POSITIVE_INFINITY);
    }
    if (!Vector3f.isValidVector(max)) {
        max.set(Vector3f.NEGATIVE_INFINITY);
    }

    for(int i=0;i<num;i++) {
        if( emitParticle(min, max) == null ) break;
    }

    bbox.setMinMax(min, max);
    this.setBoundRefresh();

    vars.release();
}
 
Example 3
Source File: MyParticleEmitter.java    From OpenRTS with MIT License 5 votes vote down vote up
/**
 * Instantly emits all the particles possible to be emitted. Any particles
 * which are currently inactive will be spawned immediately.
 */
@Override
public void emitAllParticles() {
    // Force world transform to update
    this.getWorldTransform();

    TempVars vars = TempVars.get();

    BoundingBox bbox = (BoundingBox) this.getMesh().getBound();

    Vector3f min = vars.vect1;
    Vector3f max = vars.vect2;

    bbox.getMin(min);
    bbox.getMax(max);

    if (!Vector3f.isValidVector(min)) {
        min.set(Vector3f.POSITIVE_INFINITY);
    }
    if (!Vector3f.isValidVector(max)) {
        max.set(Vector3f.NEGATIVE_INFINITY);
    }

    while (emitParticle(min, max) != null);

    bbox.setMinMax(min, max);
    this.setBoundRefresh();

    vars.release();
}
 
Example 4
Source File: Octnode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void expandBoxToContainTri(BoundingBox bbox, OCTTriangle t){
    Vector3f min = bbox.getMin(null);
    Vector3f max = bbox.getMax(null);
    BoundingBox.checkMinMax(min, max, t.get1());
    BoundingBox.checkMinMax(min, max, t.get2());
    BoundingBox.checkMinMax(min, max, t.get3());
    bbox.setMinMax(min, max);
}
 
Example 5
Source File: BIHTree.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setMinMax(BoundingBox bbox, boolean doMin, int axis, float value) {
    Vector3f min = bbox.getMin(null);
    Vector3f max = bbox.getMax(null);

    if (doMin) {
        min.set(axis, value);
    } else {
        max.set(axis, value);
    }

    bbox.setMinMax(min, max);
}
 
Example 6
Source File: ParticleEmitter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Instantly emits all the particles possible to be emitted. Any particles
 * which are currently inactive will be spawned immediately.
 */
public void emitAllParticles() {
    // Force world transform to update
    this.getWorldTransform();

    TempVars vars = TempVars.get();

    BoundingBox bbox = (BoundingBox) this.getMesh().getBound();

    Vector3f min = vars.vect1;
    Vector3f max = vars.vect2;

    bbox.getMin(min);
    bbox.getMax(max);

    if (!Vector3f.isValidVector(min)) {
        min.set(Vector3f.POSITIVE_INFINITY);
    }
    if (!Vector3f.isValidVector(max)) {
        max.set(Vector3f.NEGATIVE_INFINITY);
    }

    while (emitParticle(min, max) != null);

    bbox.setMinMax(min, max);
    this.setBoundRefresh();

    vars.release();
}
 
Example 7
Source File: ShadowUtil.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
     * Updates the shadow camera to properly contain the given points (which
     * contain the eye camera frustum corners)
     *
     * @param shadowCam
     * @param points
     */
    public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) {
        boolean ortho = shadowCam.isParallelProjection();
        shadowCam.setProjectionMatrix(null);

        if (ortho) {
            shadowCam.setFrustum(-1, 1, -1, 1, 1, -1);
        } else {
            shadowCam.setFrustumPerspective(45, 1, 1, 150);
        }

        Matrix4f viewProjMatrix = shadowCam.getViewProjectionMatrix();
        Matrix4f projMatrix = shadowCam.getProjectionMatrix();

        BoundingBox splitBB = computeBoundForPoints(points, viewProjMatrix);

        TempVars vars = TempVars.get();

        Vector3f splitMin = splitBB.getMin(vars.vect1);
        Vector3f splitMax = splitBB.getMax(vars.vect2);

//        splitMin.z = 0;

        // Create the crop matrix.
        float scaleX, scaleY, scaleZ;
        float offsetX, offsetY, offsetZ;

        scaleX = 2.0f / (splitMax.x - splitMin.x);
        scaleY = 2.0f / (splitMax.y - splitMin.y);
        offsetX = -0.5f * (splitMax.x + splitMin.x) * scaleX;
        offsetY = -0.5f * (splitMax.y + splitMin.y) * scaleY;
        scaleZ = 1.0f / (splitMax.z - splitMin.z);
        offsetZ = -splitMin.z * scaleZ;

        Matrix4f cropMatrix = vars.tempMat4;
        cropMatrix.set(scaleX, 0f, 0f, offsetX,
                0f, scaleY, 0f, offsetY,
                0f, 0f, scaleZ, offsetZ,
                0f, 0f, 0f, 1f);


        Matrix4f result = new Matrix4f();
        result.set(cropMatrix);
        result.multLocal(projMatrix);

        vars.release();
        shadowCam.setProjectionMatrix(result);
    }
 
Example 8
Source File: ShadowUtil.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
     * Updates the shadow camera to properly contain the given
     * points (which contain the eye camera frustum corners)
     *
     * @param occluders
     * @param lightCam
     * @param points
     */
    public static void updateShadowCamera(Camera shadowCam, Vector3f[] points) {
        boolean ortho = shadowCam.isParallelProjection();
        shadowCam.setProjectionMatrix(null);

        if (ortho) {
            shadowCam.setFrustum(-1, 1, -1, 1, 1, -1);
        } else {
            shadowCam.setFrustumPerspective(45, 1, 1, 150);
        }

        Matrix4f viewProjMatrix = shadowCam.getViewProjectionMatrix();
        Matrix4f projMatrix = shadowCam.getProjectionMatrix();

        BoundingBox splitBB = computeBoundForPoints(points, viewProjMatrix);

        Vector3f splitMin = splitBB.getMin(null);
        Vector3f splitMax = splitBB.getMax(null);

//        splitMin.z = 0;

        // Create the crop matrix.
        float scaleX, scaleY, scaleZ;
        float offsetX, offsetY, offsetZ;

        scaleX = 2.0f / (splitMax.x - splitMin.x);
        scaleY = 2.0f / (splitMax.y - splitMin.y);
        offsetX = -0.5f * (splitMax.x + splitMin.x) * scaleX;
        offsetY = -0.5f * (splitMax.y + splitMin.y) * scaleY;
        scaleZ = 1.0f / (splitMax.z - splitMin.z);
        offsetZ = -splitMin.z * scaleZ;

        Matrix4f cropMatrix = new Matrix4f(scaleX, 0f, 0f, offsetX,
                0f, scaleY, 0f, offsetY,
                0f, 0f, scaleZ, offsetZ,
                0f, 0f, 0f, 1f);


        Matrix4f result = new Matrix4f();
        result.set(cropMatrix);
        result.multLocal(projMatrix);

        shadowCam.setProjectionMatrix(result);
    }