Search in sources :

Example 1 with ActionListener

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

the class TerrainTestTile method setupKeys.

private void setupKeys() {
    flyCam.setMoveSpeed(100);
    inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(actionListener, "wireframe");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 2 with ActionListener

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

the class TestDepthStencil method simpleInitApp.

@Override
public void simpleInitApp() {
    int w = settings.getWidth();
    int h = settings.getHeight();
    //setup framebuffer
    fb = new FrameBuffer(w, h, 1);
    Texture2D fbTex = new Texture2D(w, h, Format.RGB8);
    fb.setDepthBuffer(Format.Depth24Stencil8);
    fb.setColorTexture(fbTex);
    // setup framebuffer's scene
    Sphere sphMesh = new Sphere(20, 20, 1);
    Material solidColor = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    final Geometry sphere = new Geometry("sphere", sphMesh);
    sphere.setMaterial(solidColor);
    fbNode.attachChild(sphere);
    sphere.addControl(new AbstractControl() {

        @Override
        protected void controlUpdate(float tpf) {
            Material mat = sphere.getMaterial();
            mat.getAdditionalRenderState().setStencil(enableStencil, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.StencilOperation.Keep, RenderState.TestFunction.Never, RenderState.TestFunction.Never);
        }

        @Override
        protected void controlRender(RenderManager rm, ViewPort vp) {
        }
    });
    //setup main scene
    Picture p = new Picture("Picture");
    p.setPosition(0, 0);
    p.setWidth(w);
    p.setHeight(h);
    p.setTexture(assetManager, fbTex, false);
    rootNode.attachChild(p);
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if (enableStencil) {
                    enableStencil = false;
                    System.out.println("Stencil Enabled (model should be hidden)");
                } else {
                    enableStencil = true;
                    System.out.println("Stencil Disabled (model should be visible)");
                }
            }
        }
    };
    inputManager.addListener(acl, "toggle");
    System.out.println("Press space to toggle stencil");
}
Also used : Texture2D(com.jme3.texture.Texture2D) KeyTrigger(com.jme3.input.controls.KeyTrigger) AbstractControl(com.jme3.scene.control.AbstractControl) Material(com.jme3.material.Material) FrameBuffer(com.jme3.texture.FrameBuffer) Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Picture(com.jme3.ui.Picture) ViewPort(com.jme3.renderer.ViewPort) RenderManager(com.jme3.renderer.RenderManager)

Example 3 with ActionListener

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

the class TestPostWaterLake method simpleInitApp.

public void simpleInitApp() {
    this.flyCam.setMoveSpeed(10);
    cam.setLocation(new Vector3f(-27.0f, 1.0f, 75.0f));
    //  cam.setRotation(new Quaternion(0.03f, 0.9f, 0f, 0.4f));
    // load sky
    rootNode.attachChild(SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", false));
    File file = new File("wildhouse.zip");
    if (file.exists()) {
        useHttp = false;
    }
    // load the level from zip or http zip
    if (useHttp) {
        assetManager.registerLocator("http://jmonkeyengine.googlecode.com/files/wildhouse.zip", HttpZipLocator.class);
    } else {
        assetManager.registerLocator("wildhouse.zip", ZipLocator.class);
    }
    Spatial scene = assetManager.loadModel("main.scene");
    rootNode.attachChild(scene);
    DirectionalLight sun = new DirectionalLight();
    Vector3f lightDir = new Vector3f(-0.37352666f, -0.50444174f, -0.7784704f);
    sun.setDirection(lightDir);
    sun.setColor(ColorRGBA.White.clone().multLocal(2));
    scene.addLight(sun);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    final WaterFilter water = new WaterFilter(rootNode, lightDir);
    water.setWaterHeight(-20);
    water.setUseFoam(false);
    water.setUseRipples(false);
    water.setDeepWaterColor(ColorRGBA.Brown);
    water.setWaterColor(ColorRGBA.Brown.mult(2.0f));
    water.setWaterTransparency(0.2f);
    water.setMaxAmplitude(0.3f);
    water.setWaveScale(0.008f);
    water.setSpeed(0.7f);
    water.setShoreHardness(1.0f);
    water.setRefractionConstant(0.2f);
    water.setShininess(0.3f);
    water.setSunScale(1.0f);
    water.setColorExtinction(new Vector3f(10.0f, 20.0f, 30.0f));
    fpp.addFilter(water);
    viewPort.addProcessor(fpp);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                if (water.isUseHQShoreline()) {
                    water.setUseHQShoreline(false);
                } else {
                    water.setUseHQShoreline(true);
                }
            }
        }
    }, "HQ");
    inputManager.addMapping("HQ", new KeyTrigger(keyInput.KEY_SPACE));
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WaterFilter(com.jme3.water.WaterFilter) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) File(java.io.File)

Example 4 with ActionListener

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

the class TestCinematic method initInputs.

private void initInputs() {
    inputManager.addMapping("togglePause", new KeyTrigger(keyInput.KEY_RETURN));
    inputManager.addMapping("navFwd", new KeyTrigger(keyInput.KEY_RIGHT));
    inputManager.addMapping("navBack", new KeyTrigger(keyInput.KEY_LEFT));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("togglePause") && keyPressed) {
                if (cinematic.getPlayState() == PlayState.Playing) {
                    cinematic.pause();
                    time = cinematic.getTime();
                } else {
                    cinematic.play();
                }
            }
            if (cinematic.getPlayState() != PlayState.Playing) {
                if (name.equals("navFwd") && keyPressed) {
                    time += 0.25;
                    FastMath.clamp(time, 0, cinematic.getInitialDuration());
                    cinematic.setTime(time);
                }
                if (name.equals("navBack") && keyPressed) {
                    time -= 0.25;
                    FastMath.clamp(time, 0, cinematic.getInitialDuration());
                    cinematic.setTime(time);
                }
            }
        }
    };
    inputManager.addListener(acl, "togglePause", "navFwd", "navBack");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 5 with ActionListener

use of com.jme3.input.controls.ActionListener 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)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)50 ActionListener (com.jme3.input.controls.ActionListener)44 Vector3f (com.jme3.math.Vector3f)27 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)18 Geometry (com.jme3.scene.Geometry)16 DirectionalLight (com.jme3.light.DirectionalLight)15 Material (com.jme3.material.Material)14 Spatial (com.jme3.scene.Spatial)13 AnalogListener (com.jme3.input.controls.AnalogListener)11 Quaternion (com.jme3.math.Quaternion)11 FilterPostProcessor (com.jme3.post.FilterPostProcessor)10 Node (com.jme3.scene.Node)10 Sphere (com.jme3.scene.shape.Sphere)10 Box (com.jme3.scene.shape.Box)9 AmbientLight (com.jme3.light.AmbientLight)7 BitmapText (com.jme3.font.BitmapText)6 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)5 ChaseCamera (com.jme3.input.ChaseCamera)4 ColorRGBA (com.jme3.math.ColorRGBA)4 Vector2f (com.jme3.math.Vector2f)4