Search in sources :

Example 41 with ActionListener

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

the class TestJoystick method simpleInitApp.

@Override
public void simpleInitApp() {
    getFlyByCamera().setEnabled(false);
    Joystick[] joysticks = inputManager.getJoysticks();
    if (joysticks == null)
        throw new IllegalStateException("Cannot find any joysticks!");
    try {
        PrintWriter out = new PrintWriter(new FileWriter("joysticks-" + System.currentTimeMillis() + ".txt"));
        dumpJoysticks(joysticks, out);
        out.close();
    } catch (IOException e) {
        throw new RuntimeException("Error writing joystick dump", e);
    }
    int gamepadSize = cam.getHeight() / 2;
    float scale = gamepadSize / 512.0f;
    gamepad = new GamepadView();
    gamepad.setLocalTranslation(cam.getWidth() - gamepadSize - (scale * 20), 0, 0);
    gamepad.setLocalScale(scale, scale, scale);
    guiNode.attachChild(gamepad);
    joystickInfo = new Node("joystickInfo");
    joystickInfo.setLocalTranslation(0, cam.getHeight(), 0);
    guiNode.attachChild(joystickInfo);
    // Add a raw listener because it's eisier to get all joystick events
    // this way.
    inputManager.addRawInputListener(new JoystickEventListener());
    // add action listener for mouse click 
    // to all easier custom mapping
    inputManager.addMapping("mouseClick", new MouseButtonTrigger(mouseInput.BUTTON_LEFT));
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                pickGamePad(getInputManager().getCursorPosition());
            }
        }
    }, "mouseClick");
}
Also used : FileWriter(java.io.FileWriter) Node(com.jme3.scene.Node) IOException(java.io.IOException) Joystick(com.jme3.input.Joystick) ActionListener(com.jme3.input.controls.ActionListener) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) PrintWriter(java.io.PrintWriter)

Example 42 with ActionListener

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

the class HelloPhysics method initInputs.

/** Add InputManager action: Left click triggers shooting. */
private void initInputs() {
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
}
Also used : MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 43 with ActionListener

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

the class RefEnv method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(-2.3324413f, 2.9567573f, 4.6054406f));
    cam.setRotation(new Quaternion(0.06310794f, 0.9321281f, -0.29613864f, 0.1986369f));
    Spatial sc = assetManager.loadModel("Scenes/PBR/spheres.j3o");
    rootNode.attachChild(sc);
    rootNode.getChild("Scene").setCullHint(Spatial.CullHint.Always);
    ref = new Node("reference pictures");
    refDE = new Picture("refDE");
    refDE.setHeight(cam.getHeight());
    refDE.setWidth(cam.getWidth());
    refDE.setImage(assetManager, "jme3test/light/pbr/spheresRefDE.png", false);
    refM = new Picture("refM");
    refM.setImage(assetManager, "jme3test/light/pbr/spheresRefM.png", false);
    refM.setHeight(cam.getHeight());
    refM.setWidth(cam.getWidth());
    ref.attachChild(refDE);
    stateManager.attach(new EnvironmentCamera());
    inputManager.addMapping("tex", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("switch", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("ref", new KeyTrigger(KeyInput.KEY_R));
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("tex") && isPressed) {
                if (tex == null) {
                    return;
                }
                if (tex.getParent() == null) {
                    guiNode.attachChild(tex);
                } else {
                    tex.removeFromParent();
                }
            }
            if (name.equals("switch") && isPressed) {
                switchMat(rootNode.getChild("Scene"));
            }
            if (name.equals("ref") && isPressed) {
                if (ref.getParent() == null) {
                    guiNode.attachChild(ref);
                } else {
                    ref.removeFromParent();
                }
            }
        }
    }, "tex", "switch", "ref");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) Quaternion(com.jme3.math.Quaternion) Spatial(com.jme3.scene.Spatial) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) Picture(com.jme3.ui.Picture) Vector3f(com.jme3.math.Vector3f) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 44 with ActionListener

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

the class TestPBRLighting method simpleInitApp.

@Override
public void simpleInitApp() {
    assetManager.registerLoader(KTXLoader.class, "ktx");
    viewPort.setBackgroundColor(ColorRGBA.White);
    modelNode = (Node) new Node("modelNode");
    model = (Geometry) assetManager.loadModel("Models/Tank/tank.j3o");
    MikktspaceTangentGenerator.generate(model);
    modelNode.attachChild(model);
    dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    rootNode.addLight(dl);
    dl.setColor(ColorRGBA.White);
    rootNode.attachChild(modelNode);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    //        fpp.addFilter(new FXAAFilter());
    fpp.addFilter(new ToneMapFilter(Vector3f.UNIT_XYZ.mult(4.0f)));
    //        fpp.addFilter(new SSAOFilter(0.5f, 3, 0.2f, 0.2f));
    viewPort.addProcessor(fpp);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Sky_Cloudy.hdr", SkyFactory.EnvMapType.EquirectMap);
    Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Path.hdr", SkyFactory.EnvMapType.EquirectMap);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/Bright/BrightSky.dds", SkyFactory.EnvMapType.CubeMap);
    //Spatial sky = SkyFactory.createSky(assetManager, "Textures/Sky/road.hdr", SkyFactory.EnvMapType.EquirectMap);
    rootNode.attachChild(sky);
    pbrMat = assetManager.loadMaterial("Models/Tank/tank.j3m");
    model.setMaterial(pbrMat);
    final EnvironmentCamera envCam = new EnvironmentCamera(128, new Vector3f(0, 3f, 0));
    stateManager.attach(envCam);
    //        EnvironmentManager envManager = new EnvironmentManager();
    //        stateManager.attach(envManager);
    //       envManager.setScene(rootNode);
    LightsDebugState debugState = new LightsDebugState();
    stateManager.attach(debugState);
    ChaseCamera chaser = new ChaseCamera(cam, modelNode, inputManager);
    chaser.setDragToRotate(true);
    chaser.setMinVerticalRotation(-FastMath.HALF_PI);
    chaser.setMaxDistance(1000);
    chaser.setSmoothMotion(true);
    chaser.setRotationSensitivity(10);
    chaser.setZoomSensitivity(5);
    flyCam.setEnabled(false);
    //flyCam.setMoveSpeed(100);
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("debug") && isPressed) {
                if (tex == null) {
                    return;
                }
                if (tex.getParent() == null && tex2.getParent() == null) {
                    guiNode.attachChild(tex);
                } else if (tex2.getParent() == null) {
                    tex.removeFromParent();
                    guiNode.attachChild(tex2);
                } else {
                    tex2.removeFromParent();
                }
            }
            if (name.equals("up") && isPressed) {
                model.move(0, tpf * 100f, 0);
            }
            if (name.equals("down") && isPressed) {
                model.move(0, -tpf * 100f, 0);
            }
            if (name.equals("left") && isPressed) {
                model.move(0, 0, tpf * 100f);
            }
            if (name.equals("right") && isPressed) {
                model.move(0, 0, -tpf * 100f);
            }
            if (name.equals("light") && isPressed) {
                dl.setDirection(cam.getDirection().normalize());
            }
        }
    }, "toggle", "light", "up", "down", "left", "right", "debug");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("light", new KeyTrigger(KeyInput.KEY_F));
    inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("left", new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("right", new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("debug", new KeyTrigger(KeyInput.KEY_D));
    MaterialDebugAppState debug = new MaterialDebugAppState();
    debug.registerBinding("Common/MatDefs/Light/PBRLighting.frag", rootNode);
    getStateManager().attach(debug);
}
Also used : MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) ChaseCamera(com.jme3.input.ChaseCamera) FilterPostProcessor(com.jme3.post.FilterPostProcessor) ToneMapFilter(com.jme3.post.filters.ToneMapFilter) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) EnvironmentCamera(com.jme3.environment.EnvironmentCamera) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f)

Example 45 with ActionListener

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

the class HelloInput method initKeys.

/** Custom Keybinding: Map named actions to inputs. */
private void initKeys() {
    /** You can map one or several inputs to one named mapping. */
    inputManager.addMapping("Pause", new KeyTrigger(keyInput.KEY_P));
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_K));
    // spacebar!
    inputManager.addMapping(// spacebar!
    "Rotate", // spacebar!
    new KeyTrigger(KeyInput.KEY_SPACE), // left click!
    new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    /** Add the named mappings to the action listeners. */
    inputManager.addListener(actionListener, "Pause");
    inputManager.addListener(analogListener, "Left", "Right", "Rotate");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)48 ActionListener (com.jme3.input.controls.ActionListener)39 Vector3f (com.jme3.math.Vector3f)21 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)14 DirectionalLight (com.jme3.light.DirectionalLight)14 Geometry (com.jme3.scene.Geometry)13 Material (com.jme3.material.Material)12 Spatial (com.jme3.scene.Spatial)10 Sphere (com.jme3.scene.shape.Sphere)10 Quaternion (com.jme3.math.Quaternion)9 FilterPostProcessor (com.jme3.post.FilterPostProcessor)9 Node (com.jme3.scene.Node)8 Box (com.jme3.scene.shape.Box)8 AnalogListener (com.jme3.input.controls.AnalogListener)7 AmbientLight (com.jme3.light.AmbientLight)7 BitmapText (com.jme3.font.BitmapText)5 BulletAppState (com.jme3.bullet.BulletAppState)4 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)4 Vector2f (com.jme3.math.Vector2f)4 ParticleEmitter (com.jme3.effect.ParticleEmitter)3