Search in sources :

Example 61 with KeyTrigger

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

the class TestSoftParticles method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(-7.2221026f, 4.1183004f, 7.759811f));
    cam.setRotation(new Quaternion(0.06152846f, 0.91236454f, -0.1492115f, 0.37621948f));
    flyCam.setMoveSpeed(10);
    // -------- floor
    Box b = new Box(10, 0.1f, 10);
    Geometry geom = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Gray);
    mat.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    geom.setMaterial(mat);
    rootNode.attachChild(geom);
    Box b2 = new Box(1, 1, 1);
    Geometry geom2 = new Geometry("Box", b2);
    Material mat2 = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat2.setColor("Color", ColorRGBA.DarkGray);
    geom2.setMaterial(mat2);
    rootNode.attachChild(geom2);
    geom2.setLocalScale(0.1f, 0.2f, 1);
    fpp = new FilterPostProcessor(assetManager);
    tbf = new TranslucentBucketFilter(true);
    fpp.addFilter(tbf);
    int samples = context.getSettings().getSamples();
    if (samples > 0) {
        fpp.setNumSamples(samples);
    }
    viewPort.addProcessor(fpp);
    particleNode = new Node("particleNode");
    rootNode.attachChild(particleNode);
    createParticles();
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed && name.equals("toggle")) {
                //     tbf.setEnabled(!tbf.isEnabled());     
                softParticles = !softParticles;
                if (softParticles) {
                    viewPort.addProcessor(fpp);
                } else {
                    viewPort.removeProcessor(fpp);
                }
            }
        }
    }, "toggle");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    // emit again
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed && name.equals("refire")) {
                //fpp.removeFilter(tbf); // <-- add back in to fix
                particleNode.detachAllChildren();
                createParticles();
            //fpp.addFilter(tbf);
            }
        }
    }, "refire");
    inputManager.addMapping("refire", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
}
Also used : TranslucentBucketFilter(com.jme3.post.filters.TranslucentBucketFilter) Quaternion(com.jme3.math.Quaternion) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) FilterPostProcessor(com.jme3.post.FilterPostProcessor) Geometry(com.jme3.scene.Geometry) ActionListener(com.jme3.input.controls.ActionListener) Vector3f(com.jme3.math.Vector3f) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 62 with KeyTrigger

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

the class CubeField method Keys.

/**
     * Sets up the keyboard bindings
     */
private void Keys() {
    inputManager.addMapping("START", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addListener(this, "START", "Left", "Right");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 63 with KeyTrigger

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

the class TestBitmapFont method simpleInitApp.

@Override
public void simpleInitApp() {
    inputManager.addMapping("WordWrap", new KeyTrigger(KeyInput.KEY_TAB));
    inputManager.addListener(keyListener, "WordWrap");
    inputManager.addRawInputListener(textListener);
    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    txt.setSize(fnt.getPreferredSize() * 2f);
    txt.setText(txtB);
    txt.setLocalTranslation(0, txt.getHeight(), 0);
    guiNode.attachChild(txt);
    txt2 = new BitmapText(fnt, false);
    txt2.setSize(fnt.getPreferredSize() * 1.2f);
    txt2.setText("Text without restriction. \nText without restriction. Text without restriction. Text without restriction");
    txt2.setLocalTranslation(0, txt2.getHeight(), 0);
    guiNode.attachChild(txt2);
    txt3 = new BitmapText(fnt, false);
    txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
    txt3.setText("Press Tab to toggle word-wrap. type text and enter to input text");
    txt3.setLocalTranslation(0, settings.getHeight() / 2, 0);
    guiNode.attachChild(txt3);
}
Also used : BitmapText(com.jme3.font.BitmapText) KeyTrigger(com.jme3.input.controls.KeyTrigger) Rectangle(com.jme3.font.Rectangle) BitmapFont(com.jme3.font.BitmapFont)

Example 64 with KeyTrigger

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

the class TestWalkingChar method setupKeys.

private void setupKeys() {
    inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(this, "wireframe");
    inputManager.addMapping("CharLeft", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("CharRight", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("CharUp", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("CharDown", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("CharSpace", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("CharShoot", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(this, "CharLeft");
    inputManager.addListener(this, "CharRight");
    inputManager.addListener(this, "CharUp");
    inputManager.addListener(this, "CharDown");
    inputManager.addListener(this, "CharSpace");
    inputManager.addListener(this, "CharShoot");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 65 with KeyTrigger

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

the class TestManyLightsSingle method simpleInitApp.

@Override
public void simpleInitApp() {
    renderManager.setPreferredLightMode(lm);
    renderManager.setSinglePassLightBatchSize(6);
    flyCam.setMoveSpeed(10);
    Node scene = (Node) assetManager.loadModel("Scenes/ManyLights/Main.scene");
    rootNode.attachChild(scene);
    Node n = (Node) rootNode.getChild(0);
    final LightList lightList = n.getWorldLightList();
    final Geometry g = (Geometry) n.getChild("Grid-geom-1");
    g.getMaterial().setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    /* A colored lit cube. Needs light source! */
    Box boxMesh = new Box(1f, 1f, 1f);
    final Geometry boxGeo = new Geometry("Colored Box", boxMesh);
    Material boxMat = g.getMaterial().clone();
    boxMat.clearParam("DiffuseMap");
    boxMat.setBoolean("UseMaterialColors", true);
    boxMat.setColor("Ambient", new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    boxMat.setColor("Diffuse", ColorRGBA.Blue);
    boxGeo.setMaterial(boxMat);
    final Node cubeNodes = new Node();
    n.attachChild(cubeNodes);
    int nb = 0;
    for (Light light : lightList) {
        nb++;
        PointLight p = (PointLight) light;
        if (nb > 60) {
            n.removeLight(light);
        } else {
            LightNode ln = new LightNode("l", light);
            n.attachChild(ln);
            ln.setLocalTranslation(p.getPosition());
            int rand = FastMath.nextRandomInt(0, 3);
            switch(rand) {
                case 0:
                    light.setColor(ColorRGBA.Red);
                    //   ln.addControl(new MoveControl(5f));
                    break;
                case 1:
                    light.setColor(ColorRGBA.Yellow);
                    //    ln.addControl(new MoveControl(5f));
                    break;
                case 2:
                    light.setColor(ColorRGBA.Green);
                    //ln.addControl(new MoveControl(-5f));
                    break;
                case 3:
                    light.setColor(ColorRGBA.Orange);
                    //ln.addControl(new MoveControl(-5f));
                    break;
            }
        }
        Geometry b = boxGeo.clone(false);
        cubeNodes.attachChild(b);
        b.setLocalTranslation(p.getPosition().x, 2, p.getPosition().z);
    }
    //        cam.setLocation(new Vector3f(3.1893547f, 17.977385f, 30.8378f));
    //        cam.setRotation(new Quaternion(0.14317635f, 0.82302624f, -0.23777823f, 0.49557027f));
    cam.setLocation(new Vector3f(-1.8901939f, 29.34097f, 73.07533f));
    cam.setRotation(new Quaternion(0.0021000702f, 0.971012f, -0.23886925f, 0.008527749f));
    BasicProfilerState profiler = new BasicProfilerState(true);
    profiler.setGraphScale(1000f);
    //  getStateManager().attach(profiler);
    //        guiNode.setCullHint(CullHint.Always);
    flyCam.setDragToRotate(true);
    flyCam.setMoveSpeed(50);
    final MaterialDebugAppState debug = new MaterialDebugAppState();
    stateManager.attach(debug);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("toggle") && isPressed) {
                if (lm == TechniqueDef.LightMode.SinglePass) {
                    lm = TechniqueDef.LightMode.MultiPass;
                    helloText.setText("(Multi pass)");
                } else {
                    lm = TechniqueDef.LightMode.SinglePass;
                    helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
                }
                renderManager.setPreferredLightMode(lm);
                reloadScene(g, boxGeo, cubeNodes);
            }
            if (name.equals("lightsUp") && isPressed) {
                renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() + 1);
                helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
            }
            if (name.equals("lightsDown") && isPressed) {
                renderManager.setSinglePassLightBatchSize(renderManager.getSinglePassLightBatchSize() - 1);
                helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
            }
            if (name.equals("toggleOnOff") && isPressed) {
                for (final Light light : lightList) {
                    if (light instanceof AmbientLight) {
                        continue;
                    }
                    light.setEnabled(!light.isEnabled());
                }
            }
        }
    }, "toggle", "lightsUp", "lightsDown", "toggleOnOff");
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("lightsUp", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("lightsDown", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("toggleOnOff", new KeyTrigger(KeyInput.KEY_L));
    SpotLight spot = new SpotLight();
    spot.setDirection(new Vector3f(-1f, -1f, -1f).normalizeLocal());
    spot.setColor(ColorRGBA.Blue.mult(5));
    spot.setSpotOuterAngle(FastMath.DEG_TO_RAD * 20);
    spot.setSpotInnerAngle(FastMath.DEG_TO_RAD * 5);
    spot.setPosition(new Vector3f(10, 10, 20));
    rootNode.addLight(spot);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, 1));
    rootNode.addLight(dl);
    AmbientLight al = new AmbientLight();
    al.setColor(new ColorRGBA(0.2f, 0.2f, 0.2f, 1f));
    rootNode.addLight(al);
    /**
         * Write text on the screen (HUD)
         */
    guiNode.detachAllChildren();
    guiFont = assetManager.loadFont("Interface/Fonts/Default.fnt");
    helloText = new BitmapText(guiFont, false);
    helloText.setSize(guiFont.getCharSet().getRenderedSize());
    helloText.setText("(Single pass) nb lights per batch : " + renderManager.getSinglePassLightBatchSize());
    helloText.setLocalTranslation(300, helloText.getLineHeight(), 0);
    guiNode.attachChild(helloText);
}
Also used : Quaternion(com.jme3.math.Quaternion) MaterialDebugAppState(com.jme3.util.MaterialDebugAppState) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) KeyTrigger(com.jme3.input.controls.KeyTrigger) Box(com.jme3.scene.shape.Box) Material(com.jme3.material.Material) SpotLight(com.jme3.light.SpotLight) BasicProfilerState(com.jme3.app.BasicProfilerState) Geometry(com.jme3.scene.Geometry) ColorRGBA(com.jme3.math.ColorRGBA) ActionListener(com.jme3.input.controls.ActionListener) BitmapText(com.jme3.font.BitmapText) LightNode(com.jme3.scene.LightNode) DirectionalLight(com.jme3.light.DirectionalLight) SpotLight(com.jme3.light.SpotLight) PointLight(com.jme3.light.PointLight) Light(com.jme3.light.Light) AmbientLight(com.jme3.light.AmbientLight) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) LightList(com.jme3.light.LightList) PointLight(com.jme3.light.PointLight) AmbientLight(com.jme3.light.AmbientLight)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)93 ActionListener (com.jme3.input.controls.ActionListener)36 Vector3f (com.jme3.math.Vector3f)30 Geometry (com.jme3.scene.Geometry)23 Material (com.jme3.material.Material)22 DirectionalLight (com.jme3.light.DirectionalLight)21 Quaternion (com.jme3.math.Quaternion)18 Spatial (com.jme3.scene.Spatial)13 FilterPostProcessor (com.jme3.post.FilterPostProcessor)11 Box (com.jme3.scene.shape.Box)11 BitmapText (com.jme3.font.BitmapText)10 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)10 Node (com.jme3.scene.Node)10 AnalogListener (com.jme3.input.controls.AnalogListener)9 ColorRGBA (com.jme3.math.ColorRGBA)9 Sphere (com.jme3.scene.shape.Sphere)8 AmbientLight (com.jme3.light.AmbientLight)7 Quad (com.jme3.scene.shape.Quad)6 ChaseCamera (com.jme3.input.ChaseCamera)4 BulletAppState (com.jme3.bullet.BulletAppState)3