Search in sources :

Example 1 with AnalogListener

use of com.jme3.input.controls.AnalogListener in project jmonkeyengine by jMonkeyEngine.

the class TestAndroidTouch method simpleInitApp.

@Override
public void simpleInitApp() {
    getViewPort().setBackgroundColor(ColorRGBA.White);
    analogFormat.setMaximumFractionDigits(3);
    analogFormat.setMinimumFractionDigits(3);
    locationFormat.setMaximumFractionDigits(0);
    locationFormat.setMinimumFractionDigits(0);
    // Setup list of triggers based on different keyboard key codes. For Android, the soft keyboard key events
    // are translated into jme key events.
    int[] keyCodes = new int[] { KeyInput.KEY_0, KeyInput.KEY_1, KeyInput.KEY_2, KeyInput.KEY_3, KeyInput.KEY_4, KeyInput.KEY_5, KeyInput.KEY_6, KeyInput.KEY_7, KeyInput.KEY_8, KeyInput.KEY_9, KeyInput.KEY_DECIMAL, KeyInput.KEY_PERIOD, KeyInput.KEY_A, KeyInput.KEY_B, KeyInput.KEY_C, KeyInput.KEY_D, KeyInput.KEY_E, KeyInput.KEY_F, KeyInput.KEY_G, KeyInput.KEY_H, KeyInput.KEY_I, KeyInput.KEY_J, KeyInput.KEY_K, KeyInput.KEY_L, KeyInput.KEY_M, KeyInput.KEY_N, KeyInput.KEY_O, KeyInput.KEY_P, KeyInput.KEY_Q, KeyInput.KEY_R, KeyInput.KEY_S, KeyInput.KEY_T, KeyInput.KEY_U, KeyInput.KEY_V, KeyInput.KEY_W, KeyInput.KEY_X, KeyInput.KEY_Y, KeyInput.KEY_Z, KeyInput.KEY_CAPITAL, KeyInput.KEY_LSHIFT, KeyInput.KEY_RSHIFT, KeyInput.KEY_UP, KeyInput.KEY_DOWN, KeyInput.KEY_LEFT, KeyInput.KEY_RIGHT };
    for (int idx = 0; idx < keyCodes.length; idx++) {
        String keyMapping = mappingKeyPrefix + KeyNames.getName(keyCodes[idx]);
        inputManager.addMapping(keyMapping, new KeyTrigger(keyCodes[idx]));
        inputManager.addListener(actionListener, keyMapping);
        logger.log(Level.INFO, "Adding key mapping: {0}", keyMapping);
    }
    // setup InputManager to trigger our listeners when the various triggers are received.
    // Touch inputs are all sent to the TouchTrigger.  To have one mapping for all touch events, use TouchInput.ALL.
    inputManager.addMapping(touchMapping, new TouchTrigger(TouchInput.ALL));
    inputManager.addListener(touchListener, touchMapping);
    // If inputManager.isSimulateMouse = true, touch events will be translated into Mouse Button and Axis events.
    // To enable this, call inputManager.setSimulateMouse(true).
    inputManager.addMapping(mappingMouseLeft, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, mappingMouseLeft);
    inputManager.addMapping(mappingMouseXNeg, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping(mappingMouseXPos, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping(mappingMouseYNeg, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping(mappingMouseYPos, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addListener(analogListener, mappingMouseXNeg, mappingMouseXPos, mappingMouseYNeg, mappingMouseYPos);
    // add raw input listener to inputManager
    inputManager.addRawInputListener(rawInputListener);
    float mouseSize = (settings.getWidth() >= settings.getHeight()) ? settings.getHeight() / 2f : settings.getWidth() / 2f;
    picMouseBackground = new Picture("Mouse Background");
    picMouseBackground.setImage(assetManager, "mouse_none.png", true);
    picMouseBackground.setWidth(mouseSize);
    picMouseBackground.setHeight(mouseSize);
    picMouseBackground.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 0f);
    picMouseLeftButton = new Picture("Mouse Button Left");
    picMouseLeftButton.setImage(assetManager, "mouse_left.png", true);
    picMouseLeftButton.setWidth(mouseSize);
    picMouseLeftButton.setHeight(mouseSize);
    picMouseLeftButton.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 1f);
    picMouseDisabled = new Picture("Mouse Disabled");
    picMouseDisabled.setImage(assetManager, "mouse_disabled.png", true);
    picMouseDisabled.setWidth(mouseSize);
    picMouseDisabled.setHeight(mouseSize);
    picMouseDisabled.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 1f);
    float phoneSize = (settings.getWidth() >= settings.getHeight()) ? settings.getHeight() / 2f : settings.getWidth() / 2f;
    // preload images to send data to gpu to avoid hesitations during run time the first time the image is displayed
    renderManager.preloadScene(picMouseBackground);
    renderManager.preloadScene(picMouseLeftButton);
    renderManager.preloadScene(picMouseDisabled);
    guiNode.attachChild(picMouseBackground);
    if (inputManager.isSimulateMouse()) {
        picMouseDisabled.removeFromParent();
    } else {
        guiNode.attachChild(picMouseDisabled);
    }
    textMouseLabel = new BitmapText(guiFont, false);
    textMouseLabel.setSize(mouseSize / 10f);
    textMouseLabel.setColor(ColorRGBA.Blue);
    textMouseLabel.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 5f));
    textMouseLabel.setAlignment(BitmapFont.Align.Center);
    textMouseLabel.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    textMouseLabel.setText("Mouse Analog\nand Position");
    textMouseLabel.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize * 1.25f, 1f);
    guiNode.attachChild(textMouseLabel);
    textMouseAnalog = new BitmapText(guiFont, false);
    textMouseAnalog.setSize(mouseSize / 10f);
    textMouseAnalog.setColor(ColorRGBA.Blue);
    textMouseAnalog.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textMouseAnalog.setAlignment(BitmapFont.Align.Center);
    textMouseAnalog.setVerticalAlignment(BitmapFont.VAlign.Center);
    textMouseAnalog.setText("0.000, 0.000");
    textMouseAnalog.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f, 2f);
    guiNode.attachChild(textMouseAnalog);
    textMouseLocation = new BitmapText(guiFont, false);
    textMouseLocation.setSize(mouseSize / 10f);
    textMouseLocation.setColor(ColorRGBA.Blue);
    textMouseLocation.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textMouseLocation.setAlignment(BitmapFont.Align.Center);
    textMouseLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textMouseLocation.setText("0, 0");
    textMouseLocation.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f - mouseSize / 10f, 2f);
    guiNode.attachChild(textMouseLocation);
    textCursorLocation = new BitmapText(guiFont, false);
    textCursorLocation.setSize(mouseSize / 10f);
    textCursorLocation.setColor(ColorRGBA.Blue);
    textCursorLocation.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textCursorLocation.setAlignment(BitmapFont.Align.Center);
    textCursorLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textCursorLocation.setText("0, 0");
    textCursorLocation.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f - mouseSize / 10f * 2f, 2f);
    guiNode.attachChild(textCursorLocation);
    textKeyPressed = new BitmapText(guiFont, false);
    textKeyPressed.setSize(mouseSize / 10f);
    textKeyPressed.setColor(ColorRGBA.Blue);
    textKeyPressed.setBox(new Rectangle(0f, 0f, settings.getWidth(), mouseSize / 10f));
    textKeyPressed.setAlignment(BitmapFont.Align.Center);
    textKeyPressed.setVerticalAlignment(BitmapFont.VAlign.Top);
    textKeyPressed.setText("Last Key Pressed: None");
    textKeyPressed.setLocalTranslation(0f, settings.getHeight() - mouseSize / 10f, 2f);
    guiNode.attachChild(textKeyPressed);
    picPhone = new Picture("Phone");
    picPhone.setImage(assetManager, "phone_landscape.png", true);
    picPhone.setWidth(phoneSize);
    picPhone.setHeight(phoneSize);
    picPhone.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, 0f, 1f);
    guiNode.attachChild(picPhone);
    textPhoneLocation = new BitmapText(guiFont, false);
    textPhoneLocation.setSize(phoneSize / 10f);
    textPhoneLocation.setColor(ColorRGBA.White);
    textPhoneLocation.setBox(new Rectangle(0f, 0f, phoneSize, phoneSize / 10f));
    textPhoneLocation.setAlignment(BitmapFont.Align.Center);
    textPhoneLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textPhoneLocation.setText("0, 0");
    textPhoneLocation.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, phoneSize * 0.5f, 2f);
    guiNode.attachChild(textPhoneLocation);
    textPhoneLabel = new BitmapText(guiFont, false);
    textPhoneLabel.setSize(phoneSize / 10f);
    textPhoneLabel.setColor(ColorRGBA.Blue);
    textPhoneLabel.setBox(new Rectangle(0f, 0f, phoneSize, phoneSize / 10f));
    textPhoneLabel.setAlignment(BitmapFont.Align.Center);
    textPhoneLabel.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    textPhoneLabel.setText("Touch Location");
    textPhoneLabel.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, picPhone.getLocalTranslation().y + phoneSize * 0.75f, 1f);
    guiNode.attachChild(textPhoneLabel);
    renderManager.preloadScene(picPhone);
}
Also used : BitmapText(com.jme3.font.BitmapText) Picture(com.jme3.ui.Picture) Rectangle(com.jme3.font.Rectangle)

Example 2 with AnalogListener

use of com.jme3.input.controls.AnalogListener in project jmonkeyengine by jMonkeyEngine.

the class TestColorApp method simpleInitApp.

@Override
public void simpleInitApp() {
    // Lights
    DirectionalLight sun = new DirectionalLight();
    Vector3f sunPosition = new Vector3f(1, -1, 1);
    sun.setDirection(sunPosition);
    sun.setColor(new ColorRGBA(1f, 1f, 1f, 1f));
    rootNode.addLight(sun);
    //DirectionalLightShadowFilter sun_renderer = new DirectionalLightShadowFilter(assetManager, 2048, 4);
    DirectionalLightShadowRenderer sun_renderer = new DirectionalLightShadowRenderer(assetManager, 2048, 1);
    sun_renderer.setLight(sun);
    viewPort.addProcessor(sun_renderer);
    //        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    //        fpp.addFilter(sun_renderer);
    //        viewPort.addProcessor(fpp);
    rootNode.setShadowMode(RenderQueue.ShadowMode.CastAndReceive);
    // Camera
    viewPort.setBackgroundColor(new ColorRGBA(.6f, .6f, .6f, 1f));
    ChaseCamera chaseCam = new ChaseCamera(cam, inputManager);
    // Objects
    // Ground Object
    final Geometry groundBoxWhite = new Geometry("Box", new Box(7.5f, 7.5f, .25f));
    float[] f = { -FastMath.PI / 2, 3 * FastMath.PI / 2, 0f };
    groundBoxWhite.setLocalRotation(new Quaternion(f));
    groundBoxWhite.move(7.5f, -.75f, 7.5f);
    final Material groundMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    groundMaterial.setColor("Diffuse", new ColorRGBA(.9f, .9f, .9f, .9f));
    groundBoxWhite.setMaterial(groundMaterial);
    groundBoxWhite.addControl(chaseCam);
    rootNode.attachChild(groundBoxWhite);
    // Planter
    Geometry planterBox = new Geometry("Box", new Box(.5f, .5f, .5f));
    final Material planterMaterial = new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md");
    planterMaterial.setTexture("DiffuseMap", assetManager.loadTexture("Textures/Terrain/BrickWall/BrickWall.jpg"));
    planterBox.setMaterial(groundMaterial);
    planterBox.setLocalTranslation(10, 0, 9);
    rootNode.attachChild(planterBox);
    // Action!
    inputManager.addMapping("on", new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addMapping("off", new KeyTrigger(KeyInput.KEY_X));
    inputManager.addListener(new AnalogListener() {

        @Override
        public void onAnalog(String s, float v, float v1) {
            if (s.equals("on")) {
                groundBoxWhite.setMaterial(planterMaterial);
            }
            if (s.equals("off")) {
                groundBoxWhite.setMaterial(groundMaterial);
            }
        }
    }, "on", "off");
    inputEnabled = true;
}
Also used : Quaternion(com.jme3.math.Quaternion) KeyTrigger(com.jme3.input.controls.KeyTrigger) ChaseCamera(com.jme3.input.ChaseCamera) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) DirectionalLightShadowRenderer(com.jme3.shadow.DirectionalLightShadowRenderer) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 3 with AnalogListener

use of com.jme3.input.controls.AnalogListener in project jmonkeyengine by jMonkeyEngine.

the class TestConeVSFrustum method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    frustumCam = cam.clone();
    frustumCam.setFrustumFar(25);
    Vector3f[] points = new Vector3f[8];
    for (int i = 0; i < 8; i++) {
        points[i] = new Vector3f();
    }
    ShadowUtil.updateFrustumPoints2(frustumCam, points);
    WireFrustum frustumShape = new WireFrustum(points);
    Geometry frustum = new Geometry("frustum", frustumShape);
    frustum.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    rootNode.attachChild(frustum);
    rootNode.addLight(new DirectionalLight());
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.2f));
    rootNode.addLight(al);
    Grid grid = new Grid(50, 50, 5);
    Geometry gridGeom = new Geometry("grid", grid);
    gridGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    gridGeom.getMaterial().setColor("Color", ColorRGBA.Gray);
    rootNode.attachChild(gridGeom);
    gridGeom.setLocalTranslation(-125, -25, -125);
    //        flyCam.setMoveSpeed(30);
    //        flyCam.setDragToRotate(true);
    //        cam.setLocation(new Vector3f(56.182674f, 19.037334f, 7.093905f));
    //        cam.setRotation(new Quaternion(0.0816657f, -0.82228005f, 0.12213967f, 0.5497892f));
    spotLight = new SpotLight();
    spotLight.setSpotRange(25);
    spotLight.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    float radius = FastMath.tan(spotLight.getSpotOuterAngle()) * spotLight.getSpotRange();
    Cylinder cylinder = new Cylinder(5, 16, 0, radius, spotLight.getSpotRange(), true, false);
    geom = new Geometry("light", cylinder);
    geom.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"));
    geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
    geom.getMaterial().setColor("Ambient", ColorRGBA.DarkGray);
    geom.getMaterial().setBoolean("UseMaterialColors", true);
    final LightNode ln = new LightNode("lb", spotLight);
    ln.attachChild(geom);
    geom.setLocalTranslation(0, -spotLight.getSpotRange() / 2f, 0);
    geom.rotate(-FastMath.HALF_PI, 0, 0);
    rootNode.attachChild(ln);
    //        ln.rotate(FastMath.QUARTER_PI, 0, 0);
    //      ln.setLocalTranslation(0, 0, -16);
    inputManager.addMapping("click", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("shift", new KeyTrigger(KeyInput.KEY_LSHIFT), new KeyTrigger(KeyInput.KEY_RSHIFT));
    inputManager.addMapping("middleClick", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    inputManager.addMapping("up", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping("down", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping("left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping("right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    final Node camTarget = new Node("CamTarget");
    rootNode.attachChild(camTarget);
    ChaseCameraAppState chaser = new ChaseCameraAppState();
    chaser.setTarget(camTarget);
    chaser.setMaxDistance(150);
    chaser.setDefaultDistance(70);
    chaser.setDefaultHorizontalRotation(FastMath.HALF_PI);
    chaser.setMinVerticalRotation(-FastMath.PI);
    chaser.setMaxVerticalRotation(FastMath.PI * 2);
    chaser.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    stateManager.attach(chaser);
    flyCam.setEnabled(false);
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            Spatial s = null;
            float mult = 1;
            if (moving) {
                s = ln;
            }
            if (panning) {
                s = camTarget;
                mult = -1;
            }
            if ((moving || panning) && s != null) {
                if (shift) {
                    if (name.equals("left")) {
                        tmp.set(cam.getDirection());
                        s.rotate(tmpQuat.fromAngleAxis(value, tmp));
                    }
                    if (name.equals("right")) {
                        tmp.set(cam.getDirection());
                        s.rotate(tmpQuat.fromAngleAxis(-value, tmp));
                    }
                } else {
                    value *= MOVE_SPEED * mult;
                    if (name.equals("up")) {
                        tmp.set(cam.getUp()).multLocal(value);
                        s.move(tmp);
                    }
                    if (name.equals("down")) {
                        tmp.set(cam.getUp()).multLocal(-value);
                        s.move(tmp);
                    }
                    if (name.equals("left")) {
                        tmp.set(cam.getLeft()).multLocal(value);
                        s.move(tmp);
                    }
                    if (name.equals("right")) {
                        tmp.set(cam.getLeft()).multLocal(-value);
                        s.move(tmp);
                    }
                }
            }
        }
    }, "up", "down", "left", "right");
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("click")) {
                if (isPressed) {
                    moving = true;
                } else {
                    moving = false;
                }
            }
            if (name.equals("middleClick")) {
                if (isPressed) {
                    panning = true;
                } else {
                    panning = false;
                }
            }
            if (name.equals("shift")) {
                if (isPressed) {
                    shift = true;
                } else {
                    shift = false;
                }
            }
        }
    }, "click", "middleClick", "shift");
    /**
         * An unshaded textured cube. // * Uses texture from jme3-test-data
         * library!
         */
    Box boxMesh = new Box(1f, 1f, 1f);
    boxGeo = new Geometry("A Textured Box", boxMesh);
    Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture monkeyTex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    boxMat.setTexture("ColorMap", monkeyTex);
    boxGeo.setMaterial(boxMat);
    //        rootNode.attachChild(boxGeo);
    //
    //boxGeo2 = boxGeo.clone();
    //rootNode.attachChild(boxGeo2); 
    System.err.println("light " + spotLight.getPosition());
}
Also used : Grid(com.jme3.scene.debug.Grid) KeyTrigger(com.jme3.input.controls.KeyTrigger) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) SpotLight(com.jme3.light.SpotLight) Texture(com.jme3.texture.Texture) LightNode(com.jme3.scene.LightNode) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) ChaseCameraAppState(com.jme3.app.ChaseCameraAppState) Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WireFrustum(com.jme3.scene.debug.WireFrustum) AnalogListener(com.jme3.input.controls.AnalogListener) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) AmbientLight(com.jme3.light.AmbientLight)

Example 4 with AnalogListener

use of com.jme3.input.controls.AnalogListener in project jmonkeyengine by jMonkeyEngine.

the class TestTriangleCollision method simpleInitApp.

@Override
public void simpleInitApp() {
    // Create two boxes
    Mesh mesh1 = new Box(0.5f, 0.5f, 0.5f);
    geom1 = new Geometry("Box", mesh1);
    geom1.move(2, 2, -.5f);
    Material m1 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    m1.setColor("Color", ColorRGBA.Blue);
    geom1.setMaterial(m1);
    rootNode.attachChild(geom1);
    // load a character from jme3test-test-data
    golem = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    golem.scale(0.5f);
    golem.setLocalTranslation(-1.0f, -1.5f, -0.6f);
    // We must add a light to make the model visible
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    golem.addLight(sun);
    rootNode.attachChild(golem);
    // Create input
    inputManager.addMapping("MoveRight", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("MoveLeft", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("MoveUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("MoveDown", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addListener(analogListener, new String[] { "MoveRight", "MoveLeft", "MoveUp", "MoveDown" });
}
Also used : Geometry(com.jme3.scene.Geometry) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) KeyTrigger(com.jme3.input.controls.KeyTrigger) Mesh(com.jme3.scene.Mesh) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material)

Example 5 with AnalogListener

use of com.jme3.input.controls.AnalogListener in project jmonkeyengine by jMonkeyEngine.

the class TestDepthOfField method simpleInitApp.

@Override
public void simpleInitApp() {
    Node mainScene = new Node("Main Scene");
    rootNode.attachChild(mainScene);
    createTerrain(mainScene);
    DirectionalLight sun = new DirectionalLight();
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(1.7f));
    mainScene.addLight(sun);
    DirectionalLight l = new DirectionalLight();
    l.setDirection(Vector3f.UNIT_Y.mult(-1));
    l.setColor(ColorRGBA.White.clone().multLocal(0.3f));
    mainScene.addLight(l);
    flyCam.setMoveSpeed(50);
    cam.setFrustumFar(3000);
    cam.setLocation(new Vector3f(-700, 100, 300));
    cam.setRotation(new Quaternion().fromAngles(new float[] { FastMath.PI * 0.06f, FastMath.PI * 0.65f, 0 }));
    Spatial sky = SkyFactory.createSky(assetManager, "Scenes/Beach/FullskiesSunset0068.dds", false);
    sky.setLocalScale(350);
    mainScene.attachChild(sky);
    fpp = new FilterPostProcessor(assetManager);
    //     fpp.setNumSamples(4);
    int numSamples = getContext().getSettings().getSamples();
    if (numSamples > 0) {
        fpp.setNumSamples(numSamples);
    }
    dofFilter = new DepthOfFieldFilter();
    dofFilter.setFocusDistance(0);
    dofFilter.setFocusRange(50);
    dofFilter.setBlurScale(1.4f);
    fpp.addFilter(dofFilter);
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (name.equals("toggle")) {
                    dofFilter.setEnabled(!dofFilter.isEnabled());
                }
            }
        }
    }, "toggle");
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("blurScaleUp")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() + 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("blurScaleDown")) {
                dofFilter.setBlurScale(dofFilter.getBlurScale() - 0.01f);
                System.out.println("blurScale : " + dofFilter.getBlurScale());
            }
            if (name.equals("focusRangeUp")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() + 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusRangeDown")) {
                dofFilter.setFocusRange(dofFilter.getFocusRange() - 1f);
                System.out.println("focusRange : " + dofFilter.getFocusRange());
            }
            if (name.equals("focusDistanceUp")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() + 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
            if (name.equals("focusDistanceDown")) {
                dofFilter.setFocusDistance(dofFilter.getFocusDistance() - 1f);
                System.out.println("focusDistance : " + dofFilter.getFocusDistance());
            }
        }
    }, "blurScaleUp", "blurScaleDown", "focusRangeUp", "focusRangeDown", "focusDistanceUp", "focusDistanceDown");
    inputManager.addMapping("toggle", new KeyTrigger(keyInput.KEY_SPACE));
    inputManager.addMapping("blurScaleUp", new KeyTrigger(keyInput.KEY_U));
    inputManager.addMapping("blurScaleDown", new KeyTrigger(keyInput.KEY_J));
    inputManager.addMapping("focusRangeUp", new KeyTrigger(keyInput.KEY_I));
    inputManager.addMapping("focusRangeDown", new KeyTrigger(keyInput.KEY_K));
    inputManager.addMapping("focusDistanceUp", new KeyTrigger(keyInput.KEY_O));
    inputManager.addMapping("focusDistanceDown", new KeyTrigger(keyInput.KEY_L));
}
Also used : Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) DepthOfFieldFilter(com.jme3.post.filters.DepthOfFieldFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) DirectionalLight(com.jme3.light.DirectionalLight) AnalogListener(com.jme3.input.controls.AnalogListener)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)14 AnalogListener (com.jme3.input.controls.AnalogListener)13 ActionListener (com.jme3.input.controls.ActionListener)11 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)6 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)6 Vector3f (com.jme3.math.Vector3f)6 DirectionalLight (com.jme3.light.DirectionalLight)5 Material (com.jme3.material.Material)4 Geometry (com.jme3.scene.Geometry)4 Node (com.jme3.scene.Node)4 ColorRGBA (com.jme3.math.ColorRGBA)3 Spatial (com.jme3.scene.Spatial)3 Box (com.jme3.scene.shape.Box)3 BitmapText (com.jme3.font.BitmapText)2 ChaseCamera (com.jme3.input.ChaseCamera)2 MouseInput (com.jme3.input.MouseInput)2 AmbientLight (com.jme3.light.AmbientLight)2 Quaternion (com.jme3.math.Quaternion)2 CfgConst (com.cas.circuit.CfgConst)1 Archive (com.cas.circuit.vo.Archive)1