Search in sources :

Example 66 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class BIHTree method collideWithRay.

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();
    }
}
Also used : CollisionResults(com.jme3.collision.CollisionResults) TempVars(com.jme3.util.TempVars)

Example 67 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method emitParticles.

/**
     * 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();
}
Also used : BoundingBox(com.jme3.bounding.BoundingBox) Vector3f(com.jme3.math.Vector3f) TempVars(com.jme3.util.TempVars)

Example 68 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class ParticleEmitter method renderFromControl.

/**
     * Callback from Control.render(), do not use.
     *
     * @param rm
     * @param vp
     */
private void renderFromControl(RenderManager rm, ViewPort vp) {
    Camera cam = vp.getCamera();
    if (meshType == ParticleMesh.Type.Point) {
        float C = cam.getProjectionMatrix().m00;
        C *= cam.getWidth() * 0.5f;
        // send attenuation params
        this.getMaterial().setFloat("Quadratic", C);
    }
    Matrix3f inverseRotation = Matrix3f.IDENTITY;
    TempVars vars = null;
    if (!worldSpace) {
        vars = TempVars.get();
        inverseRotation = this.getWorldRotation().toRotationMatrix(vars.tempMat3).invertLocal();
    }
    particleMesh.updateParticleData(particles, cam, inverseRotation);
    if (!worldSpace) {
        vars.release();
    }
}
Also used : Matrix3f(com.jme3.math.Matrix3f) Camera(com.jme3.renderer.Camera) TempVars(com.jme3.util.TempVars)

Example 69 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class LightProbeBlendingProcessor method computeBlendFactors.

private float computeBlendFactors(List<BlendFactor> blendFactors) {
    float sumBlendFactors = 0;
    for (Spatial scene : viewPort.getScenes()) {
        for (Light light : scene.getWorldLightList()) {
            if (light.getType() == Light.Type.Probe) {
                LightProbe p = (LightProbe) light;
                TempVars vars = TempVars.get();
                boolean intersect = p.intersectsFrustum(viewPort.getCamera(), vars);
                vars.release();
                //check if the probe is inside the camera frustum
                if (intersect) {
                    //is the poi inside the bounds of this probe
                    if (poi.getWorldBound().intersects(p.getBounds())) {
                        //computing the distance as we need it to check if th epoi in in the inner radius and later to compute the weight
                        float outerRadius = ((BoundingSphere) p.getBounds()).getRadius();
                        float innerRadius = outerRadius * 0.5f;
                        float distance = p.getBounds().getCenter().distance(poi.getWorldTranslation());
                        // if the poi in inside the inner range of this probe, then this probe is the only one that matters.
                        if (distance < innerRadius) {
                            blendFactors.clear();
                            blendFactors.add(new BlendFactor(p, 1.0f));
                            return 1.0f;
                        }
                        //else we need to compute the weight of this probe and collect it for blending
                        float ndf = (distance - innerRadius) / (outerRadius - innerRadius);
                        sumBlendFactors += ndf;
                        blendFactors.add(new BlendFactor(p, ndf));
                    }
                }
            }
        }
    }
    return sumBlendFactors;
}
Also used : BoundingSphere(com.jme3.bounding.BoundingSphere) Spatial(com.jme3.scene.Spatial) TempVars(com.jme3.util.TempVars)

Example 70 with TempVars

use of com.jme3.util.TempVars in project jmonkeyengine by jMonkeyEngine.

the class PoiLightProbeLightFilter 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 (light.getType() == Light.Type.Probe) {
                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;
                    }
                }
            }
            filteredLightList.add(light);
        }
        processor.populateProbe(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)

Aggregations

TempVars (com.jme3.util.TempVars)103 Vector3f (com.jme3.math.Vector3f)50 Quaternion (com.jme3.math.Quaternion)13 Matrix4f (com.jme3.math.Matrix4f)12 BoundingBox (com.jme3.bounding.BoundingBox)10 Bone (com.jme3.animation.Bone)8 Spatial (com.jme3.scene.Spatial)7 CollisionResult (com.jme3.collision.CollisionResult)6 Vector2f (com.jme3.math.Vector2f)6 FloatBuffer (java.nio.FloatBuffer)6 BoundingSphere (com.jme3.bounding.BoundingSphere)5 BoundingVolume (com.jme3.bounding.BoundingVolume)5 Transform (com.jme3.math.Transform)5 DirectionalLight (com.jme3.light.DirectionalLight)4 PointLight (com.jme3.light.PointLight)4 Geometry (com.jme3.scene.Geometry)4 SpotLight (com.jme3.light.SpotLight)3 ColorRGBA (com.jme3.math.ColorRGBA)3 Matrix3f (com.jme3.math.Matrix3f)3 Vector4f (com.jme3.math.Vector4f)3