Search in sources :

Example 61 with Camera

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

the class CameraHelper method toCamera249.

/**
     * This method converts the given structure to jme camera. Should be used form blender 2.49.
     * 
     * @param structure
     *            camera structure
     * @return jme camera object
     * @throws BlenderFileException
     *             an exception is thrown when there are problems with the
     *             blender file
     */
private Camera toCamera249(Structure structure) throws BlenderFileException {
    Camera camera = new Camera(DEFAULT_CAM_WIDTH, DEFAULT_CAM_HEIGHT);
    int type = ((Number) structure.getFieldValue("type")).intValue();
    if (type != 0 && type != 1) {
        LOGGER.log(Level.WARNING, "Unknown camera type: {0}. Perspective camera is being used!", type);
        type = 0;
    }
    // type==0 - perspective; type==1 - orthographic; perspective is used as default
    camera.setParallelProjection(type == 1);
    float aspect = 0;
    float clipsta = ((Number) structure.getFieldValue("clipsta")).floatValue();
    float clipend = ((Number) structure.getFieldValue("clipend")).floatValue();
    if (type == 0) {
        aspect = ((Number) structure.getFieldValue("lens")).floatValue();
    } else {
        aspect = ((Number) structure.getFieldValue("ortho_scale")).floatValue();
    }
    camera.setFrustumPerspective(aspect, camera.getWidth() / camera.getHeight(), clipsta, clipend);
    camera.setName(structure.getName());
    return camera;
}
Also used : Camera(com.jme3.renderer.Camera)

Example 62 with Camera

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

the class PhysicsTestHelper method createBallShooter.

/**
     * creates the necessary inputlistener and action to shoot balls from teh camera
     * @param app
     * @param rootNode
     * @param space
     */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(10);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) TextureKey(com.jme3.asset.TextureKey) ActionListener(com.jme3.input.controls.ActionListener) Material(com.jme3.material.Material) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) Texture(com.jme3.texture.Texture) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 63 with Camera

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

the class TestHoveringTank method createTerrain.

private void createTerrain() {
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matRock.setBoolean("useTriPlanarMapping", false);
    matRock.setBoolean("WardIso", true);
    matRock.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/mountains512.png");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap", grass);
    matRock.setFloat("DiffuseMap_0_scale", 64);
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_1", dirt);
    matRock.setFloat("DiffuseMap_1_scale", 16);
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_2", rock);
    matRock.setFloat("DiffuseMap_2_scale", 128);
    Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
    normalMap0.setWrap(WrapMode.Repeat);
    Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
    normalMap1.setWrap(WrapMode.Repeat);
    Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
    normalMap2.setWrap(WrapMode.Repeat);
    matRock.setTexture("NormalMap", normalMap0);
    matRock.setTexture("NormalMap_1", normalMap2);
    matRock.setTexture("NormalMap_2", normalMap2);
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
        heightmap.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    List<Camera> cameras = new ArrayList<Camera>();
    cameras.add(getCamera());
    TerrainLodControl control = new TerrainLodControl(terrain, cameras);
    terrain.addControl(control);
    terrain.setMaterial(matRock);
    terrain.setLocalScale(new Vector3f(2, 2, 2));
    // unlock it so we can edit the height
    terrain.setLocked(false);
    terrain.setShadowMode(ShadowMode.CastAndReceive);
    terrain.addControl(new RigidBodyControl(0));
    rootNode.attachChild(terrain);
    getPhysicsSpace().addAll(terrain);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) ArrayList(java.util.ArrayList) TerrainLodControl(com.jme3.terrain.geomipmap.TerrainLodControl) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) ChaseCamera(com.jme3.input.ChaseCamera) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

Example 64 with Camera

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

the class TestDepthFuncChange method simpleInitApp.

public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    flyCam.setMoveSpeed(20);
    //top of the screen
    //default depth func (less or equal) rendering.
    //2 cubes, a blue and a red. the red cube is offset by 0.2 WU to the right   
    //the red cube is put in the transparent bucket to be sure it's rendered after the blue one (but there is no transparency involved).
    //You should see a small part of the blue cube on the left and the whole red cube
    Box boxshape1 = new Box(1f, 1f, 1f);
    Geometry cube1 = new Geometry("box", boxshape1);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    cube1.setMaterial(mat);
    rootNode.attachChild(cube1);
    cube1.move(0, 1.5f, 0);
    Geometry cube2 = cube1.clone(true);
    cube2.move(0.2f, 0, 0);
    cube2.setQueueBucket(RenderQueue.Bucket.Transparent);
    cube2.getMaterial().setColor("Color", ColorRGBA.Red);
    rootNode.attachChild(cube2);
    //Bottom of the screen
    //here the 2 cubes are clonned and the depthFunc for the red cube's material is set to Less
    //You should see the whole bleu cube and a small part of the red cube on the right
    Geometry cube3 = cube1.clone();
    Geometry cube4 = cube2.clone(true);
    cube4.getMaterial().getAdditionalRenderState().setDepthFunc(RenderState.TestFunction.Less);
    cube3.move(0, -3, 0);
    cube4.move(0, -3, 0);
    rootNode.attachChild(cube3);
    rootNode.attachChild(cube4);
//Note that if you move the camera z fighting will occur but that's expected.
}
Also used : Geometry(com.jme3.scene.Geometry) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 65 with Camera

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

the class TestMultiPostWater method createTerrain.

private void createTerrain(Node rootNode) {
    matRock = new Material(assetManager, "Common/MatDefs/Terrain/TerrainLighting.j3md");
    matRock.setBoolean("useTriPlanarMapping", false);
    matRock.setBoolean("WardIso", true);
    matRock.setTexture("AlphaMap", assetManager.loadTexture("Textures/Terrain/splat/alphamap.png"));
    Texture heightMapImage = assetManager.loadTexture("Textures/Terrain/splat/pools.png");
    Texture grass = assetManager.loadTexture("Textures/Terrain/splat/grass.jpg");
    grass.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap", grass);
    matRock.setFloat("DiffuseMap_0_scale", 64);
    Texture dirt = assetManager.loadTexture("Textures/Terrain/splat/dirt.jpg");
    dirt.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_1", dirt);
    matRock.setFloat("DiffuseMap_1_scale", 16);
    Texture rock = assetManager.loadTexture("Textures/Terrain/splat/road.jpg");
    rock.setWrap(WrapMode.Repeat);
    matRock.setTexture("DiffuseMap_2", rock);
    matRock.setFloat("DiffuseMap_2_scale", 128);
    Texture normalMap0 = assetManager.loadTexture("Textures/Terrain/splat/grass_normal.jpg");
    normalMap0.setWrap(WrapMode.Repeat);
    Texture normalMap1 = assetManager.loadTexture("Textures/Terrain/splat/dirt_normal.png");
    normalMap1.setWrap(WrapMode.Repeat);
    Texture normalMap2 = assetManager.loadTexture("Textures/Terrain/splat/road_normal.png");
    normalMap2.setWrap(WrapMode.Repeat);
    matRock.setTexture("NormalMap", normalMap0);
    matRock.setTexture("NormalMap_1", normalMap2);
    matRock.setTexture("NormalMap_2", normalMap2);
    AbstractHeightMap heightmap = null;
    try {
        heightmap = new ImageBasedHeightMap(heightMapImage.getImage(), 0.25f);
        heightmap.load();
    } catch (Exception e) {
        e.printStackTrace();
    }
    terrain = new TerrainQuad("terrain", 65, 513, heightmap.getHeightMap());
    List<Camera> cameras = new ArrayList<Camera>();
    cameras.add(getCamera());
    terrain.setMaterial(matRock);
    terrain.setLocalScale(new Vector3f(5, 5, 5));
    terrain.setLocalTranslation(new Vector3f(0, -30, 0));
    // unlock it so we can edit the height
    terrain.setLocked(false);
    terrain.setShadowMode(ShadowMode.Receive);
    rootNode.attachChild(terrain);
}
Also used : AbstractHeightMap(com.jme3.terrain.heightmap.AbstractHeightMap) Vector3f(com.jme3.math.Vector3f) ArrayList(java.util.ArrayList) Material(com.jme3.material.Material) Camera(com.jme3.renderer.Camera) Texture(com.jme3.texture.Texture) TerrainQuad(com.jme3.terrain.geomipmap.TerrainQuad) ImageBasedHeightMap(com.jme3.terrain.heightmap.ImageBasedHeightMap)

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