Search in sources :

Example 16 with MouseButtonTrigger

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

the class HelloAudio method initKeys.

/** Declaring "Shoot" action, mapping it to a trigger (mouse left click). */
private void initKeys() {
    inputManager.addMapping("Shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "Shoot");
}
Also used : MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Example 17 with MouseButtonTrigger

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

the class TestChaseCameraAppState method simpleInitApp.

public void simpleInitApp() {
    // Load a teapot model
    teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");
    Material mat_tea = new Material(assetManager, "Common/MatDefs/Misc/ShowNormals.j3md");
    teaGeom.setMaterial(mat_tea);
    rootNode.attachChild(teaGeom);
    // Load a floor model
    Material mat_ground = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat_ground.setTexture("ColorMap", assetManager.loadTexture("Interface/Logo/Monkey.jpg"));
    Geometry ground = new Geometry("ground", new Quad(50, 50));
    ground.setLocalRotation(new Quaternion().fromAngleAxis(-FastMath.HALF_PI, Vector3f.UNIT_X));
    ground.setLocalTranslation(-25, -1, 25);
    ground.setMaterial(mat_ground);
    rootNode.attachChild(ground);
    //disable the flyCam
    stateManager.detach(stateManager.getState(FlyCamAppState.class));
    // Enable a chase cam  
    ChaseCameraAppState chaseCamAS = new ChaseCameraAppState();
    chaseCamAS.setTarget(teaGeom);
    stateManager.attach(chaseCamAS);
    //Uncomment this to invert the camera's vertical rotation Axis 
    //chaseCamAS.setInvertVerticalAxis(true);
    //Uncomment this to invert the camera's horizontal rotation Axis
    //chaseCamAS.setInvertHorizontalAxis(true);
    //Uncomment this to enable rotation when the middle mouse button is pressed (like Blender)
    //WARNING : setting this trigger disable the rotation on right and left mouse button click
    //chaseCamAS.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    //Uncomment this to set mutiple triggers to enable rotation of the cam
    //Here space bar and middle mouse button
    //chaseCamAS.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE),new KeyTrigger(KeyInput.KEY_SPACE));
    //registering inputs for target's movement
    registerInput();
}
Also used : Geometry(com.jme3.scene.Geometry) Quad(com.jme3.scene.shape.Quad) Quaternion(com.jme3.math.Quaternion) Material(com.jme3.material.Material) FlyCamAppState(com.jme3.app.FlyCamAppState) ChaseCameraAppState(com.jme3.app.ChaseCameraAppState)

Example 18 with MouseButtonTrigger

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

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

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

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