Search in sources :

Example 26 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 27 with ActionListener

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

the class TestBatchNodeTower method simpleInitApp.

@Override
public void simpleInitApp() {
    timer = new NanoTimer();
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    //   bulletAppState.setEnabled(false);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    brick = new Box(brickWidth, brickHeight, brickDepth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    initMaterial();
    initTower();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 25f, 8f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(80);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    rootNode.setShadowMode(ShadowMode.Off);
    batchNode.batch();
    batchNode.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(batchNode);
    shadowRenderer = new DirectionalLightShadowFilter(assetManager, 1024, 2);
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    shadowRenderer.setLight(dl);
    shadowRenderer.setLambda(0.55f);
    shadowRenderer.setShadowIntensity(0.6f);
    shadowRenderer.setShadowCompareMode(CompareMode.Hardware);
    shadowRenderer.setEdgeFilteringMode(EdgeFilteringMode.PCF4);
    FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
    fpp.addFilter(shadowRenderer);
    viewPort.addProcessor(fpp);
}
Also used : Sphere(com.jme3.scene.shape.Sphere) SphereCollisionShape(com.jme3.bullet.collision.shapes.SphereCollisionShape) NanoTimer(com.jme3.system.NanoTimer) Vector2f(com.jme3.math.Vector2f) BulletAppState(com.jme3.bullet.BulletAppState) Vector3f(com.jme3.math.Vector3f) DirectionalLight(com.jme3.light.DirectionalLight) Box(com.jme3.scene.shape.Box) FilterPostProcessor(com.jme3.post.FilterPostProcessor) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) DirectionalLightShadowFilter(com.jme3.shadow.DirectionalLightShadowFilter)

Example 28 with ActionListener

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

the class TestIK method simpleInitApp.

@Override
public void simpleInitApp() {
    super.simpleInitApp();
    final KinematicRagdollControl ikControl = model.getControl(KinematicRagdollControl.class);
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("stop") && isPressed) {
                ikControl.setEnabled(!ikControl.isEnabled());
                ikControl.setIKMode();
            }
            if (name.equals("one") && isPressed) {
                //ragdoll.setKinematicMode();
                targetPoint = model.getWorldTranslation().add(new Vector3f(0, 2, 4));
                targetNode.setLocalTranslation(targetPoint);
                ikControl.setIKTarget(ikControl.getBone("Hand.L"), targetPoint, 2);
                ikControl.setIKMode();
            }
            if (name.equals("two") && isPressed) {
                //ragdoll.setKinematicMode();
                targetPoint = model.getWorldTranslation().add(new Vector3f(-3, 3, 0));
                targetNode.setLocalTranslation(targetPoint);
                ikControl.setIKTarget(ikControl.getBone("Hand.R"), targetPoint, 3);
                ikControl.setIKMode();
            }
        }
    }, "one", "two");
    inputManager.addMapping("one", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("two", new KeyTrigger(KeyInput.KEY_2));
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H));
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) Vector3f(com.jme3.math.Vector3f) KeyTrigger(com.jme3.input.controls.KeyTrigger) KinematicRagdollControl(com.jme3.bullet.control.KinematicRagdollControl)

Example 29 with ActionListener

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

the class SimpleApplication method initialize.

@Override
public void initialize() {
    super.initialize();
    // Several things rely on having this
    guiFont = loadGuiFont();
    guiNode.setQueueBucket(Bucket.Gui);
    guiNode.setCullHint(CullHint.Never);
    viewPort.attachScene(rootNode);
    guiViewPort.attachScene(guiNode);
    if (inputManager != null) {
        // the app state is added.
        if (stateManager.getState(FlyCamAppState.class) != null) {
            flyCam = new FlyByCamera(cam);
            // odd to set this here but it did it before
            flyCam.setMoveSpeed(1f);
            stateManager.getState(FlyCamAppState.class).setCamera(flyCam);
        }
        if (context.getType() == Type.Display) {
            inputManager.addMapping(INPUT_MAPPING_EXIT, new KeyTrigger(KeyInput.KEY_ESCAPE));
        }
        if (stateManager.getState(StatsAppState.class) != null) {
            inputManager.addMapping(INPUT_MAPPING_HIDE_STATS, new KeyTrigger(KeyInput.KEY_F5));
            inputManager.addListener(actionListener, INPUT_MAPPING_HIDE_STATS);
        }
        inputManager.addListener(actionListener, INPUT_MAPPING_EXIT);
    }
    if (stateManager.getState(StatsAppState.class) != null) {
        // Some of the tests rely on having access to fpsText
        // for quick display.  Maybe a different way would be better.
        stateManager.getState(StatsAppState.class).setFont(guiFont);
        fpsText = stateManager.getState(StatsAppState.class).getFpsText();
    }
    // call user code
    simpleInitApp();
}
Also used : FlyByCamera(com.jme3.input.FlyByCamera) KeyTrigger(com.jme3.input.controls.KeyTrigger)

Example 30 with ActionListener

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

the class MaterialDebugAppState method bind.

private void bind(final Binding binding) {
    if (binding.getTrigger() instanceof FileChangedTrigger) {
        FileChangedTrigger t = (FileChangedTrigger) binding.getTrigger();
        List<Binding> b = fileTriggers.get(t);
        if (b == null) {
            t.init();
            b = new ArrayList<Binding>();
            fileTriggers.put(t, b);
        }
        b.add(binding);
    } else {
        final String actionName = binding.getActionName();
        inputManager.addListener(new ActionListener() {

            public void onAction(String name, boolean isPressed, float tpf) {
                if (actionName.equals(name) && isPressed) {
                    //reloading the material
                    binding.reload();
                }
            }
        }, actionName);
        inputManager.addMapping(actionName, binding.getTrigger());
    }
}
Also used : ActionListener(com.jme3.input.controls.ActionListener)

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