Search in sources :

Example 1 with MouseAxisTrigger

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

the class TestAndroidTouch method simpleInitApp.

@Override
public void simpleInitApp() {
    getViewPort().setBackgroundColor(ColorRGBA.White);
    analogFormat.setMaximumFractionDigits(3);
    analogFormat.setMinimumFractionDigits(3);
    locationFormat.setMaximumFractionDigits(0);
    locationFormat.setMinimumFractionDigits(0);
    // Setup list of triggers based on different keyboard key codes. For Android, the soft keyboard key events
    // are translated into jme key events.
    int[] keyCodes = new int[] { KeyInput.KEY_0, KeyInput.KEY_1, KeyInput.KEY_2, KeyInput.KEY_3, KeyInput.KEY_4, KeyInput.KEY_5, KeyInput.KEY_6, KeyInput.KEY_7, KeyInput.KEY_8, KeyInput.KEY_9, KeyInput.KEY_DECIMAL, KeyInput.KEY_PERIOD, KeyInput.KEY_A, KeyInput.KEY_B, KeyInput.KEY_C, KeyInput.KEY_D, KeyInput.KEY_E, KeyInput.KEY_F, KeyInput.KEY_G, KeyInput.KEY_H, KeyInput.KEY_I, KeyInput.KEY_J, KeyInput.KEY_K, KeyInput.KEY_L, KeyInput.KEY_M, KeyInput.KEY_N, KeyInput.KEY_O, KeyInput.KEY_P, KeyInput.KEY_Q, KeyInput.KEY_R, KeyInput.KEY_S, KeyInput.KEY_T, KeyInput.KEY_U, KeyInput.KEY_V, KeyInput.KEY_W, KeyInput.KEY_X, KeyInput.KEY_Y, KeyInput.KEY_Z, KeyInput.KEY_CAPITAL, KeyInput.KEY_LSHIFT, KeyInput.KEY_RSHIFT, KeyInput.KEY_UP, KeyInput.KEY_DOWN, KeyInput.KEY_LEFT, KeyInput.KEY_RIGHT };
    for (int idx = 0; idx < keyCodes.length; idx++) {
        String keyMapping = mappingKeyPrefix + KeyNames.getName(keyCodes[idx]);
        inputManager.addMapping(keyMapping, new KeyTrigger(keyCodes[idx]));
        inputManager.addListener(actionListener, keyMapping);
        logger.log(Level.INFO, "Adding key mapping: {0}", keyMapping);
    }
    // setup InputManager to trigger our listeners when the various triggers are received.
    // Touch inputs are all sent to the TouchTrigger.  To have one mapping for all touch events, use TouchInput.ALL.
    inputManager.addMapping(touchMapping, new TouchTrigger(TouchInput.ALL));
    inputManager.addListener(touchListener, touchMapping);
    // If inputManager.isSimulateMouse = true, touch events will be translated into Mouse Button and Axis events.
    // To enable this, call inputManager.setSimulateMouse(true).
    inputManager.addMapping(mappingMouseLeft, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, mappingMouseLeft);
    inputManager.addMapping(mappingMouseXNeg, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping(mappingMouseXPos, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping(mappingMouseYNeg, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping(mappingMouseYPos, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addListener(analogListener, mappingMouseXNeg, mappingMouseXPos, mappingMouseYNeg, mappingMouseYPos);
    // add raw input listener to inputManager
    inputManager.addRawInputListener(rawInputListener);
    float mouseSize = (settings.getWidth() >= settings.getHeight()) ? settings.getHeight() / 2f : settings.getWidth() / 2f;
    picMouseBackground = new Picture("Mouse Background");
    picMouseBackground.setImage(assetManager, "mouse_none.png", true);
    picMouseBackground.setWidth(mouseSize);
    picMouseBackground.setHeight(mouseSize);
    picMouseBackground.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 0f);
    picMouseLeftButton = new Picture("Mouse Button Left");
    picMouseLeftButton.setImage(assetManager, "mouse_left.png", true);
    picMouseLeftButton.setWidth(mouseSize);
    picMouseLeftButton.setHeight(mouseSize);
    picMouseLeftButton.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 1f);
    picMouseDisabled = new Picture("Mouse Disabled");
    picMouseDisabled.setImage(assetManager, "mouse_disabled.png", true);
    picMouseDisabled.setWidth(mouseSize);
    picMouseDisabled.setHeight(mouseSize);
    picMouseDisabled.setLocalTranslation(settings.getWidth() - mouseSize, 0f, 1f);
    float phoneSize = (settings.getWidth() >= settings.getHeight()) ? settings.getHeight() / 2f : settings.getWidth() / 2f;
    // preload images to send data to gpu to avoid hesitations during run time the first time the image is displayed
    renderManager.preloadScene(picMouseBackground);
    renderManager.preloadScene(picMouseLeftButton);
    renderManager.preloadScene(picMouseDisabled);
    guiNode.attachChild(picMouseBackground);
    if (inputManager.isSimulateMouse()) {
        picMouseDisabled.removeFromParent();
    } else {
        guiNode.attachChild(picMouseDisabled);
    }
    textMouseLabel = new BitmapText(guiFont, false);
    textMouseLabel.setSize(mouseSize / 10f);
    textMouseLabel.setColor(ColorRGBA.Blue);
    textMouseLabel.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 5f));
    textMouseLabel.setAlignment(BitmapFont.Align.Center);
    textMouseLabel.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    textMouseLabel.setText("Mouse Analog\nand Position");
    textMouseLabel.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize * 1.25f, 1f);
    guiNode.attachChild(textMouseLabel);
    textMouseAnalog = new BitmapText(guiFont, false);
    textMouseAnalog.setSize(mouseSize / 10f);
    textMouseAnalog.setColor(ColorRGBA.Blue);
    textMouseAnalog.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textMouseAnalog.setAlignment(BitmapFont.Align.Center);
    textMouseAnalog.setVerticalAlignment(BitmapFont.VAlign.Center);
    textMouseAnalog.setText("0.000, 0.000");
    textMouseAnalog.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f, 2f);
    guiNode.attachChild(textMouseAnalog);
    textMouseLocation = new BitmapText(guiFont, false);
    textMouseLocation.setSize(mouseSize / 10f);
    textMouseLocation.setColor(ColorRGBA.Blue);
    textMouseLocation.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textMouseLocation.setAlignment(BitmapFont.Align.Center);
    textMouseLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textMouseLocation.setText("0, 0");
    textMouseLocation.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f - mouseSize / 10f, 2f);
    guiNode.attachChild(textMouseLocation);
    textCursorLocation = new BitmapText(guiFont, false);
    textCursorLocation.setSize(mouseSize / 10f);
    textCursorLocation.setColor(ColorRGBA.Blue);
    textCursorLocation.setBox(new Rectangle(0f, 0f, mouseSize, mouseSize / 10f));
    textCursorLocation.setAlignment(BitmapFont.Align.Center);
    textCursorLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textCursorLocation.setText("0, 0");
    textCursorLocation.setLocalTranslation(settings.getWidth() - mouseSize, mouseSize / 2f - mouseSize / 10f * 2f, 2f);
    guiNode.attachChild(textCursorLocation);
    textKeyPressed = new BitmapText(guiFont, false);
    textKeyPressed.setSize(mouseSize / 10f);
    textKeyPressed.setColor(ColorRGBA.Blue);
    textKeyPressed.setBox(new Rectangle(0f, 0f, settings.getWidth(), mouseSize / 10f));
    textKeyPressed.setAlignment(BitmapFont.Align.Center);
    textKeyPressed.setVerticalAlignment(BitmapFont.VAlign.Top);
    textKeyPressed.setText("Last Key Pressed: None");
    textKeyPressed.setLocalTranslation(0f, settings.getHeight() - mouseSize / 10f, 2f);
    guiNode.attachChild(textKeyPressed);
    picPhone = new Picture("Phone");
    picPhone.setImage(assetManager, "phone_landscape.png", true);
    picPhone.setWidth(phoneSize);
    picPhone.setHeight(phoneSize);
    picPhone.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, 0f, 1f);
    guiNode.attachChild(picPhone);
    textPhoneLocation = new BitmapText(guiFont, false);
    textPhoneLocation.setSize(phoneSize / 10f);
    textPhoneLocation.setColor(ColorRGBA.White);
    textPhoneLocation.setBox(new Rectangle(0f, 0f, phoneSize, phoneSize / 10f));
    textPhoneLocation.setAlignment(BitmapFont.Align.Center);
    textPhoneLocation.setVerticalAlignment(BitmapFont.VAlign.Center);
    textPhoneLocation.setText("0, 0");
    textPhoneLocation.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, phoneSize * 0.5f, 2f);
    guiNode.attachChild(textPhoneLocation);
    textPhoneLabel = new BitmapText(guiFont, false);
    textPhoneLabel.setSize(phoneSize / 10f);
    textPhoneLabel.setColor(ColorRGBA.Blue);
    textPhoneLabel.setBox(new Rectangle(0f, 0f, phoneSize, phoneSize / 10f));
    textPhoneLabel.setAlignment(BitmapFont.Align.Center);
    textPhoneLabel.setVerticalAlignment(BitmapFont.VAlign.Bottom);
    textPhoneLabel.setText("Touch Location");
    textPhoneLabel.setLocalTranslation(picMouseBackground.getLocalTranslation().x - phoneSize, picPhone.getLocalTranslation().y + phoneSize * 0.75f, 1f);
    guiNode.attachChild(textPhoneLabel);
    renderManager.preloadScene(picPhone);
}
Also used : BitmapText(com.jme3.font.BitmapText) Picture(com.jme3.ui.Picture) Rectangle(com.jme3.font.Rectangle)

Example 2 with MouseAxisTrigger

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

the class TestConeVSFrustum method simpleInitApp.

@Override
public void simpleInitApp() {
    viewPort.setBackgroundColor(ColorRGBA.DarkGray);
    frustumCam = cam.clone();
    frustumCam.setFrustumFar(25);
    Vector3f[] points = new Vector3f[8];
    for (int i = 0; i < 8; i++) {
        points[i] = new Vector3f();
    }
    ShadowUtil.updateFrustumPoints2(frustumCam, points);
    WireFrustum frustumShape = new WireFrustum(points);
    Geometry frustum = new Geometry("frustum", frustumShape);
    frustum.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    rootNode.attachChild(frustum);
    rootNode.addLight(new DirectionalLight());
    AmbientLight al = new AmbientLight();
    al.setColor(ColorRGBA.White.mult(0.2f));
    rootNode.addLight(al);
    Grid grid = new Grid(50, 50, 5);
    Geometry gridGeom = new Geometry("grid", grid);
    gridGeom.setMaterial(new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md"));
    gridGeom.getMaterial().setColor("Color", ColorRGBA.Gray);
    rootNode.attachChild(gridGeom);
    gridGeom.setLocalTranslation(-125, -25, -125);
    //        flyCam.setMoveSpeed(30);
    //        flyCam.setDragToRotate(true);
    //        cam.setLocation(new Vector3f(56.182674f, 19.037334f, 7.093905f));
    //        cam.setRotation(new Quaternion(0.0816657f, -0.82228005f, 0.12213967f, 0.5497892f));
    spotLight = new SpotLight();
    spotLight.setSpotRange(25);
    spotLight.setSpotOuterAngle(10 * FastMath.DEG_TO_RAD);
    float radius = FastMath.tan(spotLight.getSpotOuterAngle()) * spotLight.getSpotRange();
    Cylinder cylinder = new Cylinder(5, 16, 0, radius, spotLight.getSpotRange(), true, false);
    geom = new Geometry("light", cylinder);
    geom.setMaterial(new Material(assetManager, "Common/MatDefs/Light/Lighting.j3md"));
    geom.getMaterial().setColor("Diffuse", ColorRGBA.White);
    geom.getMaterial().setColor("Ambient", ColorRGBA.DarkGray);
    geom.getMaterial().setBoolean("UseMaterialColors", true);
    final LightNode ln = new LightNode("lb", spotLight);
    ln.attachChild(geom);
    geom.setLocalTranslation(0, -spotLight.getSpotRange() / 2f, 0);
    geom.rotate(-FastMath.HALF_PI, 0, 0);
    rootNode.attachChild(ln);
    //        ln.rotate(FastMath.QUARTER_PI, 0, 0);
    //      ln.setLocalTranslation(0, 0, -16);
    inputManager.addMapping("click", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("shift", new KeyTrigger(KeyInput.KEY_LSHIFT), new KeyTrigger(KeyInput.KEY_RSHIFT));
    inputManager.addMapping("middleClick", new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    inputManager.addMapping("up", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping("down", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping("left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping("right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    final Node camTarget = new Node("CamTarget");
    rootNode.attachChild(camTarget);
    ChaseCameraAppState chaser = new ChaseCameraAppState();
    chaser.setTarget(camTarget);
    chaser.setMaxDistance(150);
    chaser.setDefaultDistance(70);
    chaser.setDefaultHorizontalRotation(FastMath.HALF_PI);
    chaser.setMinVerticalRotation(-FastMath.PI);
    chaser.setMaxVerticalRotation(FastMath.PI * 2);
    chaser.setToggleRotationTrigger(new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    stateManager.attach(chaser);
    flyCam.setEnabled(false);
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            Spatial s = null;
            float mult = 1;
            if (moving) {
                s = ln;
            }
            if (panning) {
                s = camTarget;
                mult = -1;
            }
            if ((moving || panning) && s != null) {
                if (shift) {
                    if (name.equals("left")) {
                        tmp.set(cam.getDirection());
                        s.rotate(tmpQuat.fromAngleAxis(value, tmp));
                    }
                    if (name.equals("right")) {
                        tmp.set(cam.getDirection());
                        s.rotate(tmpQuat.fromAngleAxis(-value, tmp));
                    }
                } else {
                    value *= MOVE_SPEED * mult;
                    if (name.equals("up")) {
                        tmp.set(cam.getUp()).multLocal(value);
                        s.move(tmp);
                    }
                    if (name.equals("down")) {
                        tmp.set(cam.getUp()).multLocal(-value);
                        s.move(tmp);
                    }
                    if (name.equals("left")) {
                        tmp.set(cam.getLeft()).multLocal(value);
                        s.move(tmp);
                    }
                    if (name.equals("right")) {
                        tmp.set(cam.getLeft()).multLocal(-value);
                        s.move(tmp);
                    }
                }
            }
        }
    }, "up", "down", "left", "right");
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (name.equals("click")) {
                if (isPressed) {
                    moving = true;
                } else {
                    moving = false;
                }
            }
            if (name.equals("middleClick")) {
                if (isPressed) {
                    panning = true;
                } else {
                    panning = false;
                }
            }
            if (name.equals("shift")) {
                if (isPressed) {
                    shift = true;
                } else {
                    shift = false;
                }
            }
        }
    }, "click", "middleClick", "shift");
    /**
         * An unshaded textured cube. // * Uses texture from jme3-test-data
         * library!
         */
    Box boxMesh = new Box(1f, 1f, 1f);
    boxGeo = new Geometry("A Textured Box", boxMesh);
    Material boxMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    Texture monkeyTex = assetManager.loadTexture("Interface/Logo/Monkey.jpg");
    boxMat.setTexture("ColorMap", monkeyTex);
    boxGeo.setMaterial(boxMat);
    //        rootNode.attachChild(boxGeo);
    //
    //boxGeo2 = boxGeo.clone();
    //rootNode.attachChild(boxGeo2); 
    System.err.println("light " + spotLight.getPosition());
}
Also used : Grid(com.jme3.scene.debug.Grid) KeyTrigger(com.jme3.input.controls.KeyTrigger) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) LightNode(com.jme3.scene.LightNode) Node(com.jme3.scene.Node) SpotLight(com.jme3.light.SpotLight) Texture(com.jme3.texture.Texture) LightNode(com.jme3.scene.LightNode) DirectionalLight(com.jme3.light.DirectionalLight) Material(com.jme3.material.Material) Box(com.jme3.scene.shape.Box) ChaseCameraAppState(com.jme3.app.ChaseCameraAppState) Geometry(com.jme3.scene.Geometry) Cylinder(com.jme3.scene.shape.Cylinder) ActionListener(com.jme3.input.controls.ActionListener) Spatial(com.jme3.scene.Spatial) WireFrustum(com.jme3.scene.debug.WireFrustum) AnalogListener(com.jme3.input.controls.AnalogListener) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) AmbientLight(com.jme3.light.AmbientLight)

Example 3 with MouseAxisTrigger

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

the class TestPbrEnv method fixFLyCamInputs.

private void fixFLyCamInputs() {
    inputManager.deleteMapping(CameraInput.FLYCAM_LEFT);
    inputManager.deleteMapping(CameraInput.FLYCAM_RIGHT);
    inputManager.deleteMapping(CameraInput.FLYCAM_UP);
    inputManager.deleteMapping(CameraInput.FLYCAM_DOWN);
    inputManager.addMapping(CameraInput.FLYCAM_LEFT, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping(CameraInput.FLYCAM_RIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping(CameraInput.FLYCAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping(CameraInput.FLYCAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addListener(flyCam, CameraInput.FLYCAM_LEFT, CameraInput.FLYCAM_RIGHT, CameraInput.FLYCAM_UP, CameraInput.FLYCAM_DOWN);
}
Also used : MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger)

Example 4 with MouseAxisTrigger

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

the class ChaseCameraAppState method initVerticalAxisInputs.

private void initVerticalAxisInputs() {
    if (!invertYaxis) {
        inputManager.addMapping(CameraInput.CHASECAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        inputManager.addMapping(CameraInput.CHASECAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    } else {
        inputManager.addMapping(CameraInput.CHASECAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
        inputManager.addMapping(CameraInput.CHASECAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    }
}
Also used : MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger)

Example 5 with MouseAxisTrigger

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

the class ChaseCameraAppState method initHorizontalAxisInput.

private void initHorizontalAxisInput() {
    if (!invertXaxis) {
        inputManager.addMapping(CameraInput.CHASECAM_MOVELEFT, new MouseAxisTrigger(MouseInput.AXIS_X, true));
        inputManager.addMapping(CameraInput.CHASECAM_MOVERIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    } else {
        inputManager.addMapping(CameraInput.CHASECAM_MOVELEFT, new MouseAxisTrigger(MouseInput.AXIS_X, false));
        inputManager.addMapping(CameraInput.CHASECAM_MOVERIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    }
}
Also used : MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger)

Aggregations

MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)13 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)7 ActionListener (com.jme3.input.controls.ActionListener)4 AnalogListener (com.jme3.input.controls.AnalogListener)4 KeyTrigger (com.jme3.input.controls.KeyTrigger)4 Vector3f (com.jme3.math.Vector3f)3 Node (com.jme3.scene.Node)3 BitmapText (com.jme3.font.BitmapText)2 MouseInput (com.jme3.input.MouseInput)2 AmbientLight (com.jme3.light.AmbientLight)2 ColorRGBA (com.jme3.math.ColorRGBA)2 Spatial (com.jme3.scene.Spatial)2 CfgConst (com.cas.circuit.CfgConst)1 Archive (com.cas.circuit.vo.Archive)1 ControlIO (com.cas.circuit.vo.ControlIO)1 ElecCompDef (com.cas.circuit.vo.ElecCompDef)1 Jack (com.cas.circuit.vo.Jack)1 Terminal (com.cas.circuit.vo.Terminal)1 Wire (com.cas.circuit.vo.Wire)1 ElecCompProxy (com.cas.circuit.vo.archive.ElecCompProxy)1