Search in sources :

Example 11 with MouseButtonTrigger

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

the class PhysicsTestHelper method createBallShooter.

/**
     * creates the necessary inputlistener and action to shoot balls from teh camera
     * @param app
     * @param rootNode
     * @param space
     */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(10);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
Also used : Sphere(com.jme3.scene.shape.Sphere) Geometry(com.jme3.scene.Geometry) TextureKey(com.jme3.asset.TextureKey) ActionListener(com.jme3.input.controls.ActionListener) Material(com.jme3.material.Material) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) Texture(com.jme3.texture.Texture) RigidBodyControl(com.jme3.bullet.control.RigidBodyControl)

Example 12 with MouseButtonTrigger

use of com.jme3.input.controls.MouseButtonTrigger 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 13 with MouseButtonTrigger

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

the class TestPhysicsCharacter method setupKeys.

private void setupKeys() {
    inputManager.addMapping("Strafe Left", new KeyTrigger(KeyInput.KEY_Q), new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addMapping("Strafe Right", new KeyTrigger(KeyInput.KEY_E), new KeyTrigger(KeyInput.KEY_X));
    inputManager.addMapping("Rotate Left", new KeyTrigger(KeyInput.KEY_A), new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Rotate Right", new KeyTrigger(KeyInput.KEY_D), new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("Walk Forward", new KeyTrigger(KeyInput.KEY_W), new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("Walk Backward", new KeyTrigger(KeyInput.KEY_S), new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Jump", new KeyTrigger(KeyInput.KEY_SPACE), new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("Shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(this, "Strafe Left", "Strafe Right");
    inputManager.addListener(this, "Rotate Left", "Rotate Right");
    inputManager.addListener(this, "Walk Forward", "Walk Backward");
    inputManager.addListener(this, "Jump", "Shoot");
}
Also used : KeyTrigger(com.jme3.input.controls.KeyTrigger) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 14 with MouseButtonTrigger

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

the class TestAndroidSensors method simpleInitApp.

@Override
public void simpleInitApp() {
    if (enableFlyByCameraRotation) {
        flyCam.setEnabled(true);
    } else {
        flyCam.setEnabled(false);
    }
    Mesh lineX = new Line(Vector3f.ZERO, Vector3f.ZERO.add(Vector3f.UNIT_X.mult(3)));
    Mesh lineY = new Line(Vector3f.ZERO, Vector3f.ZERO.add(Vector3f.UNIT_Y.mult(3)));
    Mesh lineZ = new Line(Vector3f.ZERO, Vector3f.ZERO.add(Vector3f.UNIT_Z.mult(3)));
    Geometry geoX = new Geometry("X", lineX);
    Material matX = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matX.setColor("Color", ColorRGBA.Red);
    matX.getAdditionalRenderState().setLineWidth(30);
    geoX.setMaterial(matX);
    rootNode.attachChild(geoX);
    Geometry geoY = new Geometry("Y", lineY);
    Material matY = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matY.setColor("Color", ColorRGBA.Green);
    matY.getAdditionalRenderState().setLineWidth(30);
    geoY.setMaterial(matY);
    rootNode.attachChild(geoY);
    Geometry geoZ = new Geometry("Z", lineZ);
    Material matZ = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    matZ.setColor("Color", ColorRGBA.Blue);
    matZ.getAdditionalRenderState().setLineWidth(30);
    geoZ.setMaterial(matZ);
    rootNode.attachChild(geoZ);
    Box b = new Box(1, 1, 1);
    geomZero = new Geometry("Box", b);
    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Yellow);
    Texture tex_ml = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    mat.setTexture("ColorMap", tex_ml);
    geomZero.setMaterial(mat);
    geomZero.setLocalTranslation(Vector3f.ZERO);
    geomZero.setLocalRotation(Quaternion.IDENTITY);
    rootNode.attachChild(geomZero);
    // Touch (aka MouseInput.BUTTON_LEFT) is used to record the starting
    // orientation when using absolute rotations
    inputManager.addMapping("MouseClick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(this, "MouseClick");
    Joystick[] joysticks = inputManager.getJoysticks();
    if (joysticks == null || joysticks.length < 1) {
        logger.log(Level.INFO, "Cannot find any joysticks!");
    } else {
        // Joysticks return a value of 0 to 1 based on how far the stick is
        // push on the axis. This value is then scaled based on how long
        // during the frame the joystick axis has been in that position.
        // If the joystick is push all the way for the whole frame,
        // then the value in onAnalog is equal to tpf.
        // If the joystick is push 1/2 way for the entire frame, then the
        // onAnalog value is 1/2 tpf.
        // Similarly, if the joystick is pushed to the maximum during a frame
        // the value in onAnalog will also be scaled.
        // For Android sensors, rotating the device 90deg is the same as
        // pushing an actual joystick axis to the maximum.
        logger.log(Level.INFO, "Number of joysticks: {0}", joysticks.length);
        JoystickAxis axis;
        for (Joystick joystick : joysticks) {
            // Get and display all axes in joystick.
            List<JoystickAxis> axes = joystick.getAxes();
            for (JoystickAxis joystickAxis : axes) {
                logger.log(Level.INFO, "{0} axis scan Name: {1}, LogicalId: {2}, AxisId: {3}", new Object[] { joystick.getName(), joystickAxis.getName(), joystickAxis.getLogicalId(), joystickAxis.getAxisId() });
            }
            // Get specific axis based on LogicalId of the JoystickAxis
            // If found, map axis
            axis = joystick.getAxis(SensorJoystickAxis.ORIENTATION_X);
            if (axis != null) {
                axis.assignAxis(ORIENTATION_X_PLUS, ORIENTATION_X_MINUS);
                inputManager.addListener(this, ORIENTATION_X_PLUS, ORIENTATION_X_MINUS);
                logger.log(Level.INFO, "Found {0} Joystick, assigning mapping for X axis: {1}, with max value: {2}", new Object[] { joystick.toString(), axis.toString(), ((SensorJoystickAxis) axis).getMaxRawValue() });
            }
            axis = joystick.getAxis(SensorJoystickAxis.ORIENTATION_Y);
            if (axis != null) {
                axis.assignAxis(ORIENTATION_Y_PLUS, ORIENTATION_Y_MINUS);
                inputManager.addListener(this, ORIENTATION_Y_PLUS, ORIENTATION_Y_MINUS);
                logger.log(Level.INFO, "Found {0} Joystick, assigning mapping for Y axis: {1}, with max value: {2}", new Object[] { joystick.toString(), axis.toString(), ((SensorJoystickAxis) axis).getMaxRawValue() });
            }
            axis = joystick.getAxis(SensorJoystickAxis.ORIENTATION_Z);
            if (axis != null) {
                axis.assignAxis(ORIENTATION_Z_PLUS, ORIENTATION_Z_MINUS);
                inputManager.addListener(this, ORIENTATION_Z_PLUS, ORIENTATION_Z_MINUS);
                logger.log(Level.INFO, "Found {0} Joystick, assigning mapping for Z axis: {1}, with max value: {2}", new Object[] { joystick.toString(), axis.toString(), ((SensorJoystickAxis) axis).getMaxRawValue() });
            }
            joystickMap.put(joystick.getJoyId(), joystick);
        }
    }
}
Also used : Line(com.jme3.scene.shape.Line) Geometry(com.jme3.scene.Geometry) Joystick(com.jme3.input.Joystick) Mesh(com.jme3.scene.Mesh) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) SensorJoystickAxis(com.jme3.input.SensorJoystickAxis) JoystickAxis(com.jme3.input.JoystickAxis) Texture(com.jme3.texture.Texture)

Example 15 with MouseButtonTrigger

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

Aggregations

MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)20 KeyTrigger (com.jme3.input.controls.KeyTrigger)10 Material (com.jme3.material.Material)8 Geometry (com.jme3.scene.Geometry)7 Box (com.jme3.scene.shape.Box)6 BulletAppState (com.jme3.bullet.BulletAppState)5 ActionListener (com.jme3.input.controls.ActionListener)5 Vector3f (com.jme3.math.Vector3f)5 Sphere (com.jme3.scene.shape.Sphere)5 SphereCollisionShape (com.jme3.bullet.collision.shapes.SphereCollisionShape)4 Quaternion (com.jme3.math.Quaternion)4 Vector2f (com.jme3.math.Vector2f)3 Node (com.jme3.scene.Node)3 Quad (com.jme3.scene.shape.Quad)3 Texture (com.jme3.texture.Texture)3 ChaseCameraAppState (com.jme3.app.ChaseCameraAppState)2 RigidBodyControl (com.jme3.bullet.control.RigidBodyControl)2 BitmapText (com.jme3.font.BitmapText)2 Joystick (com.jme3.input.Joystick)2 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)2