Search in sources :

Example 21 with BoundingBox

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

the class SpotLight method intersectsBox.

@Override
public boolean intersectsBox(BoundingBox box, TempVars vars) {
    if (this.spotRange > 0f) {
        // Sphere v. box collision
        if (!Intersection.intersect(box, position, spotRange)) {
            return false;
        }
    }
    Vector3f otherCenter = box.getCenter();
    Vector3f radVect = vars.vect4;
    radVect.set(box.getXExtent(), box.getYExtent(), box.getZExtent());
    float otherRadiusSquared = radVect.lengthSquared();
    float otherRadius = FastMath.sqrt(otherRadiusSquared);
    // Check if sphere is within spot angle.
    // Cone v. sphere collision.
    Vector3f E = direction.mult(otherRadius * outerAngleSinRcp, vars.vect1);
    Vector3f U = position.subtract(E, vars.vect2);
    Vector3f D = otherCenter.subtract(U, vars.vect3);
    float dsqr = D.dot(D);
    float e = direction.dot(D);
    if (e > 0f && e * e >= dsqr * outerAngleCosSqr) {
        D = otherCenter.subtract(position, vars.vect3);
        dsqr = D.dot(D);
        e = -direction.dot(D);
        if (e > 0f && e * e >= dsqr * outerAngleSinSqr) {
            return dsqr <= otherRadiusSquared;
        } else {
            return true;
        }
    }
    return false;
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 22 with BoundingBox

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

the class BIHTree method setMinMax.

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);
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 23 with BoundingBox

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

the class ParticleEmitter method updateParticleState.

private void updateParticleState(float tpf) {
    // Force world transform to update
    this.getWorldTransform();
    TempVars vars = TempVars.get();
    Vector3f min = vars.vect1.set(Vector3f.POSITIVE_INFINITY);
    Vector3f max = vars.vect2.set(Vector3f.NEGATIVE_INFINITY);
    for (int i = 0; i < particles.length; ++i) {
        Particle p = particles[i];
        if (p.life == 0) {
            //                assert i <= firstUnUsed;
            continue;
        }
        p.life -= tpf;
        if (p.life <= 0) {
            this.freeParticle(i);
            continue;
        }
        updateParticle(p, tpf, min, max);
        if (firstUnUsed < i) {
            this.swap(firstUnUsed, i);
            if (i == lastUsed) {
                lastUsed = firstUnUsed;
            }
            firstUnUsed++;
        }
    }
    // Spawns particles within the tpf timeslot with proper age
    float interval = 1f / particlesPerSec;
    float originalTpf = tpf;
    tpf += timeDifference;
    while (tpf > interval) {
        tpf -= interval;
        Particle p = emitParticle(min, max);
        if (p != null) {
            p.life -= tpf;
            if (lastPos != null && isInWorldSpace()) {
                p.position.interpolateLocal(lastPos, 1 - tpf / originalTpf);
            }
            if (p.life <= 0) {
                freeParticle(lastUsed);
            } else {
                updateParticle(p, tpf, min, max);
            }
        }
    }
    timeDifference = tpf;
    if (lastPos == null) {
        lastPos = new Vector3f();
    }
    lastPos.set(getWorldTranslation());
    //This check avoids a NaN bounds when all the particles are dead during the first update.
    if (!min.equals(Vector3f.POSITIVE_INFINITY) && !max.equals(Vector3f.NEGATIVE_INFINITY)) {
        BoundingBox bbox = (BoundingBox) this.getMesh().getBound();
        bbox.setMinMax(min, max);
        this.setBoundRefresh();
    }
    vars.release();
}
Also used : Vector3f(com.jme3.math.Vector3f) BoundingBox(com.jme3.bounding.BoundingBox) TempVars(com.jme3.util.TempVars)

Example 24 with BoundingBox

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

the class DefaultLightFilter method filterLights.

@Override
public void filterLights(Geometry geometry, LightList filteredLightList) {
    TempVars vars = TempVars.get();
    try {
        LightList worldLights = geometry.getWorldLightList();
        for (int i = 0; i < worldLights.size(); i++) {
            Light light = worldLights.get(i);
            // If this light is not enabled it will be ignored.
            if (!light.isEnabled()) {
                continue;
            }
            if (light.frustumCheckNeeded) {
                processedLights.add(light);
                light.frustumCheckNeeded = false;
                light.intersectsFrustum = light.intersectsFrustum(camera, vars);
            }
            if (!light.intersectsFrustum) {
                continue;
            }
            BoundingVolume bv = geometry.getWorldBound();
            if (bv instanceof BoundingBox) {
                if (!light.intersectsBox((BoundingBox) bv, vars)) {
                    continue;
                }
            } else if (bv instanceof BoundingSphere) {
                if (!Float.isInfinite(((BoundingSphere) bv).getRadius())) {
                    if (!light.intersectsSphere((BoundingSphere) bv, vars)) {
                        continue;
                    }
                }
            }
            if (light.getType() == Light.Type.Probe) {
                probeBlendStrat.registerProbe((LightProbe) light);
            } else {
                filteredLightList.add(light);
            }
        }
        probeBlendStrat.populateProbes(geometry, filteredLightList);
    } finally {
        vars.release();
    }
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) BoundingBox(com.jme3.bounding.BoundingBox) BoundingVolume(com.jme3.bounding.BoundingVolume) TempVars(com.jme3.util.TempVars)

Example 25 with BoundingBox

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

the class TemporalMesh method getWorldBound.

@Override
public BoundingVolume getWorldBound() {
    this.updateModelBound();
    Node parent = this.getParent();
    if (parent != null) {
        BoundingVolume bv = boundingBox.clone();
        bv.setCenter(parent.getWorldTranslation());
        return bv;
    } else {
        return boundingBox;
    }
}
Also used : Node(com.jme3.scene.Node) BoundingVolume(com.jme3.bounding.BoundingVolume)

Aggregations

BoundingBox (com.jme3.bounding.BoundingBox)42 Vector3f (com.jme3.math.Vector3f)35 Geometry (com.jme3.scene.Geometry)14 TempVars (com.jme3.util.TempVars)14 BoundingVolume (com.jme3.bounding.BoundingVolume)10 BoundingSphere (com.jme3.bounding.BoundingSphere)8 Material (com.jme3.material.Material)7 Vector2f (com.jme3.math.Vector2f)4 Texture (com.jme3.texture.Texture)4 Test (org.junit.Test)4 DirectionalLight (com.jme3.light.DirectionalLight)3 Matrix4f (com.jme3.math.Matrix4f)3 Ray (com.jme3.math.Ray)3 Node (com.jme3.scene.Node)3 Spatial (com.jme3.scene.Spatial)3 TerrainLodControl (com.jme3.terrain.geomipmap.TerrainLodControl)3 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)3 DistanceLodCalculator (com.jme3.terrain.geomipmap.lodcalc.DistanceLodCalculator)3 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)3 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)3