Search in sources :

Example 66 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class TerrainTestReadWrite method loadTerrain.

private void loadTerrain() {
    FileInputStream fis = null;
    try {
        long start = System.currentTimeMillis();
        // remove the existing terrain and detach it from the root node.
        if (terrain != null) {
            Node existingTerrain = (Node) terrain;
            existingTerrain.removeFromParent();
            existingTerrain.removeControl(TerrainLodControl.class);
            existingTerrain.detachAllChildren();
            terrain = null;
        }
        // import the saved terrain, and attach it back to the root node
        File f = new File("terrainsave.jme");
        fis = new FileInputStream(f);
        BinaryImporter imp = BinaryImporter.getInstance();
        imp.setAssetManager(assetManager);
        terrain = (TerrainQuad) imp.load(new BufferedInputStream(fis));
        rootNode.attachChild((Node) terrain);
        float duration = (System.currentTimeMillis() - start) / 1000.0f;
        System.out.println("Load took " + duration + " seconds");
        // now we have to add back the camera to the LOD control
        TerrainLodControl lodControl = ((Node) terrain).getControl(TerrainLodControl.class);
        if (lodControl != null)
            lodControl.setCamera(getCamera());
    } catch (IOException ex) {
        Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
        } catch (IOException ex) {
            Logger.getLogger(TerrainTestReadWrite.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
Also used : BinaryImporter(com.jme3.export.binary.BinaryImporter) Node(com.jme3.scene.Node) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl)

Example 67 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class SpotLight method intersectsFrustum.

@Override
public boolean intersectsFrustum(Camera cam, TempVars vars) {
    if (spotRange == 0) {
        // The algorithm below does not support infinite spot range.
        return true;
    }
    Vector3f farPoint = vars.vect1.set(position).addLocal(vars.vect2.set(direction).multLocal(spotRange));
    for (int i = 5; i >= 0; i--) {
        //check origin against the plane
        Plane plane = cam.getWorldPlane(i);
        float dot = plane.pseudoDistance(position);
        if (dot < 0) {
            // outside, check the far point against the plane   
            dot = plane.pseudoDistance(farPoint);
            if (dot < 0) {
                // outside, check the projection of the far point along the normal of the plane to the base disc perimeter of the cone
                //computing the radius of the base disc
                float farRadius = (spotRange / outerAngleCos) * outerAngleSin;
                //computing the projection direction : perpendicular to the light direction and coplanar with the direction vector and the normal vector
                Vector3f perpDirection = vars.vect2.set(direction).crossLocal(plane.getNormal()).normalizeLocal().crossLocal(direction);
                //projecting the far point on the base disc perimeter
                Vector3f projectedPoint = vars.vect3.set(farPoint).addLocal(perpDirection.multLocal(farRadius));
                //checking against the plane
                dot = plane.pseudoDistance(projectedPoint);
                if (dot < 0) {
                    // Outside, the light can be culled
                    return false;
                }
            }
        }
    }
    return true;
}
Also used : Plane(com.jme3.math.Plane) Vector3f(com.jme3.math.Vector3f)

Example 68 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class ChaseCamera method read.

/**
     * Read the camera
     * @param im
     * @throws IOException
     */
public void read(JmeImporter im) throws IOException {
    InputCapsule ic = im.getCapsule(this);
    maxDistance = ic.readFloat("maxDistance", 40);
    minDistance = ic.readFloat("minDistance", 1);
}
Also used : InputCapsule(com.jme3.export.InputCapsule)

Example 69 with Camera

use of com.jme3.renderer.Camera in project jmonkeyengine by jMonkeyEngine.

the class ChaseCamera method setSpatial.

/**
     * Sets the spacial for the camera control, should only be used internally
     * @param spatial
     */
public void setSpatial(Spatial spatial) {
    target = spatial;
    if (spatial == null) {
        return;
    }
    computePosition();
    prevPos = new Vector3f(target.getWorldTranslation());
    cam.setLocation(pos);
}
Also used : Vector3f(com.jme3.math.Vector3f)

Example 70 with Camera

use of com.jme3.renderer.Camera 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)

Aggregations

Camera (com.jme3.renderer.Camera)63 Vector3f (com.jme3.math.Vector3f)51 Material (com.jme3.material.Material)26 Geometry (com.jme3.scene.Geometry)26 Quaternion (com.jme3.math.Quaternion)23 Spatial (com.jme3.scene.Spatial)19 TempVars (com.jme3.util.TempVars)16 Box (com.jme3.scene.shape.Box)13 ViewPort (com.jme3.renderer.ViewPort)11 Node (com.jme3.scene.Node)11 DirectionalLight (com.jme3.light.DirectionalLight)10 FrameBuffer (com.jme3.texture.FrameBuffer)10 Texture (com.jme3.texture.Texture)10 FilterPostProcessor (com.jme3.post.FilterPostProcessor)9 Texture2D (com.jme3.texture.Texture2D)9 ArrayList (java.util.ArrayList)9 TerrainQuad (com.jme3.terrain.geomipmap.TerrainQuad)8 AbstractHeightMap (com.jme3.terrain.heightmap.AbstractHeightMap)8 ImageBasedHeightMap (com.jme3.terrain.heightmap.ImageBasedHeightMap)8 CameraNode (com.jme3.scene.CameraNode)7