Search in sources :

Example 16 with AnalogListener

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

the class SSAOUI method init.

private void init(InputManager inputManager) {
    System.out.println("----------------- SSAO UI Debugger --------------------");
    System.out.println("-- Sample Radius : press Y to increase, H to decrease");
    System.out.println("-- AO Intensity : press U to increase, J to decrease");
    System.out.println("-- AO scale : press I to increase, K to decrease");
    System.out.println("-- AO bias : press O to increase, P to decrease");
    System.out.println("-- Toggle AO on/off : press space bar");
    System.out.println("-- Use only AO : press Num pad 0");
    System.out.println("-- Output config declaration : press P");
    System.out.println("-------------------------------------------------------");
    inputManager.addMapping("sampleRadiusUp", new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addMapping("sampleRadiusDown", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("intensityUp", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("intensityDown", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("scaleUp", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("scaleDown", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addMapping("biasUp", new KeyTrigger(KeyInput.KEY_O));
    inputManager.addMapping("biasDown", new KeyTrigger(KeyInput.KEY_L));
    inputManager.addMapping("outputConfig", new KeyTrigger(KeyInput.KEY_P));
    inputManager.addMapping("toggleUseAO", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("toggleUseOnlyAo", new KeyTrigger(KeyInput.KEY_NUMPAD0));
    inputManager.addMapping("toggleApprox", new KeyTrigger(KeyInput.KEY_NUMPAD5));
    ActionListener acl = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggleUseAO") && keyPressed) {
                filter.setEnabled(!filter.isEnabled());
                // filter.setUseAo(!filter.isUseAo());
                System.out.println("use AO : " + filter.isEnabled());
            }
            if (name.equals("toggleApprox") && keyPressed) {
                filter.setApproximateNormals(!filter.isApproximateNormals());
                System.out.println("Approximate Normals : " + filter.isApproximateNormals());
            }
            if (name.equals("toggleUseOnlyAo") && keyPressed) {
                filter.setUseOnlyAo(!filter.isUseOnlyAo());
                System.out.println("use Only AO : " + filter.isUseOnlyAo());
            }
            if (name.equals("outputConfig") && keyPressed) {
                System.out.println("new SSAOFilter(" + filter.getSampleRadius() + "f," + filter.getIntensity() + "f," + filter.getScale() + "f," + filter.getBias() + "f);");
            }
        }
    };
    AnalogListener anl = new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if (name.equals("sampleRadiusUp")) {
                filter.setSampleRadius(filter.getSampleRadius() + 0.01f);
                System.out.println("Sample Radius : " + filter.getSampleRadius());
            }
            if (name.equals("sampleRadiusDown")) {
                filter.setSampleRadius(filter.getSampleRadius() - 0.01f);
                System.out.println("Sample Radius : " + filter.getSampleRadius());
            }
            if (name.equals("intensityUp")) {
                filter.setIntensity(filter.getIntensity() + 0.01f);
                System.out.println("Intensity : " + filter.getIntensity());
            }
            if (name.equals("intensityDown")) {
                filter.setIntensity(filter.getIntensity() - 0.01f);
                System.out.println("Intensity : " + filter.getIntensity());
            }
            if (name.equals("scaleUp")) {
                filter.setScale(filter.getScale() + 0.01f);
                System.out.println("scale : " + filter.getScale());
            }
            if (name.equals("scaleDown")) {
                filter.setScale(filter.getScale() - 0.01f);
                System.out.println("scale : " + filter.getScale());
            }
            if (name.equals("biasUp")) {
                filter.setBias(filter.getBias() + 0.001f);
                System.out.println("bias : " + filter.getBias());
            }
            if (name.equals("biasDown")) {
                filter.setBias(filter.getBias() - 0.001f);
                System.out.println("bias : " + filter.getBias());
            }
        }
    };
    inputManager.addListener(acl, "toggleUseAO", "toggleApprox", "toggleUseOnlyAo", "outputConfig");
    inputManager.addListener(anl, "sampleRadiusUp", "sampleRadiusDown", "intensityUp", "intensityDown", "scaleUp", "scaleDown", "biasUp", "biasDown");
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 17 with AnalogListener

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

the class TestParallaxPBR method simpleInitApp.

@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(-15.445636f, 30.162927f, 60.252777f));
    cam.setRotation(new Quaternion(0.05173137f, 0.92363626f, -0.13454558f, 0.35513034f));
    flyCam.setMoveSpeed(30);
    setupLighting();
    setupSkyBox();
    setupFloor();
    setupSignpost();
    inputManager.addListener(new AnalogListener() {

        public void onAnalog(String name, float value, float tpf) {
            if ("heightUP".equals(name)) {
                parallaxHeigh += 0.01;
                mat.setFloat("ParallaxHeight", parallaxHeigh);
            }
            if ("heightDown".equals(name)) {
                parallaxHeigh -= 0.01;
                parallaxHeigh = Math.max(parallaxHeigh, 0);
                mat.setFloat("ParallaxHeight", parallaxHeigh);
            }
        }
    }, "heightUP", "heightDown");
    inputManager.addMapping("heightUP", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addMapping("heightDown", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addListener(new ActionListener() {

        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed && "toggleSteep".equals(name)) {
                steep = !steep;
                mat.setBoolean("SteepParallax", steep);
            }
        }
    }, "toggleSteep");
    inputManager.addMapping("toggleSteep", new KeyTrigger(KeyInput.KEY_SPACE));
}
Also used : ActionListener(com.jme3.input.controls.ActionListener) KeyTrigger(com.jme3.input.controls.KeyTrigger) AnalogListener(com.jme3.input.controls.AnalogListener)

Example 18 with AnalogListener

use of com.jme3.input.controls.AnalogListener in project chordatlas by twak.

the class Tweed method simpleInitApp.

public void simpleInitApp() {
    // TweedSettings.load( new File ( Tweed.DATA ) );
    point = new PointLight();
    point.setEnabled(true);
    point.setColor(ColorRGBA.White.mult(4));
    point.setRadius(50);
    rootNode.addLight(point);
    sun = new DirectionalLight();
    // sun.setDirection(new Vector3f(-0.0f, -1f, -0f).normalizeLocal());
    sun.setDirection(new Vector3f(-0.1f, -0.7f, -1.0f).normalizeLocal());
    sun.setColor(new ColorRGBA(1f, 0.95f, 0.99f, 1f));
    rootNode.addLight(sun);
    // enable multiple lights
    renderManager.setPreferredLightMode(LightMode.SinglePass);
    renderManager.setSinglePassLightBatchSize(16);
    ambient = new AmbientLight();
    rootNode.addLight(ambient);
    setAmbient(0);
    setDisplayFps(false);
    setDisplayStatView(false);
    clearBackground();
    buildBackground();
    getFlyByCamera().setDragToRotate(true);
    setTool(tools[0]);
    debug = new Node("dbg");
    rootNode.attachChild(debug);
    // String folder = ; // data-source
    // SpotLightShadowRenderer shadows = new SpotLightShadowRenderer(assetManager, 1024);
    // shadows.setLight(sun);
    // shadows.setShadowIntensity(0.3f);
    // shadows.setEdgeFilteringMode(EdgeFilteringMode.PCF8);
    // viewPort.addProcessor(shadows);
    cam.setLocation(TweedSettings.settings.cameraLocation);
    cam.setRotation(TweedSettings.settings.cameraOrientation);
    setFov(0);
    setCameraSpeed(0);
    if (false) {
        // TweedSettings.settings.SSAO ) {
        FilterPostProcessor fpp = new FilterPostProcessor(assetManager);
        SSAOFilter filter = new SSAOFilter(0.50997847f, 1.440001f, 1.39999998f, 0);
        // fpp.addFilter( new ColorOverlayFilter( ColorRGBA.Magenta ));
        fpp.addFilter(filter);
        fpp.addFilter(new FXAAFilter());
        viewPort.addProcessor(fpp);
    }
    TweedSettings.loadDefault();
    inputManager.addMapping(MOUSE_MOVE, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping(MOUSE_MOVE, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping(MOUSE_MOVE, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping(MOUSE_MOVE, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addListener(moveListener, MOUSE_MOVE);
    inputManager.addMapping(CLICK, new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addListener(analogListener, CLICK);
    inputManager.addMapping(SPEED_UP, new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping(SPEED_DOWN, new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping(AMBIENT_UP, new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping(AMBIENT_DOWN, new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping(FOV_UP, new KeyTrigger(KeyInput.KEY_PGUP));
    inputManager.addMapping(FOV_DOWN, new KeyTrigger(KeyInput.KEY_PGDN));
    inputManager.addMapping(TOGGLE_ORTHO, new KeyTrigger(KeyInput.KEY_O));
    inputManager.addListener(new com.jme3.input.controls.ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (name == SPEED_UP)
                setCameraSpeed(+1);
            else
                setCameraSpeed(-1);
        }
    }, SPEED_UP, SPEED_DOWN);
    inputManager.addListener(new com.jme3.input.controls.ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (!isPressed)
                return;
            if (name == AMBIENT_UP)
                setAmbient(+1);
            else
                setAmbient(-1);
        }
    }, AMBIENT_UP, AMBIENT_DOWN);
    inputManager.addListener(new com.jme3.input.controls.ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (!isPressed)
                return;
            if (name == FOV_UP)
                setFov(+1);
            else
                setFov(-1);
        }
    }, FOV_UP, FOV_DOWN);
    inputManager.addListener(new com.jme3.input.controls.ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if (isPressed) {
                TweedSettings.settings.ortho = !TweedSettings.settings.ortho;
                setCameraPerspective();
            }
        }
    }, TOGGLE_ORTHO);
}
Also used : SSAOFilter(com.jme3.post.ssao.SSAOFilter) FXAAFilter(com.jme3.post.filters.FXAAFilter) Node(com.jme3.scene.Node) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) KeyTrigger(com.jme3.input.controls.KeyTrigger) FilterPostProcessor(com.jme3.post.FilterPostProcessor) ColorRGBA(com.jme3.math.ColorRGBA) DirectionalLight(com.jme3.light.DirectionalLight) Vector3f(com.jme3.math.Vector3f) PointLight(com.jme3.light.PointLight) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) AmbientLight(com.jme3.light.AmbientLight)

Example 19 with AnalogListener

use of com.jme3.input.controls.AnalogListener in project TeachingInSimulation by ScOrPiOzzy.

the class CircuitState method bindCircuitBoardEvents.

private void bindCircuitBoardEvents() {
    // 给电路板添加监听
    addMapping("CONNECT_ON_DESKTOP_AXIR_X+", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    addMapping("CONNECT_ON_DESKTOP_AXIR_X-", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    addMapping("CONNECT_ON_DESKTOP_AXIR_Y+", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    addMapping("CONNECT_ON_DESKTOP_AXIR_Y-", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    String[] hoverMapping = new String[] { "CONNECT_ON_DESKTOP_AXIR_X+", "CONNECT_ON_DESKTOP_AXIR_X-", "CONNECT_ON_DESKTOP_AXIR_Y+", "CONNECT_ON_DESKTOP_AXIR_Y-" };
    addListener((AnalogListener) (name, value, tpf) -> {
        if (state == null) {
            return;
        }
        // 先判断鼠标是否在元器件上
        collision = JmeUtil.getCollisionFromCursor(rootCompNode, cam, inputManager);
        // 如果没有宣导元器件
        if (collision == null) {
            // 再尝试和桌面碰撞
            collision = JmeUtil.getCollisionFromCursor(desktop, cam, inputManager);
        }
        if (collision == null) {
            return;
        }
        Vector3f point = collision.getContactPoint();
        // 离电路板略高一些。
        point.addLocal(0, minHeight, 0);
        if (state == State.Starting) {
            // 开头
            Vector3f project = point.subtract(startLine1.getStart()).project(dir);
            if (project.dot(dir) < minLen) {
                return;
            }
            Vector3f line1EndPoint = startLine1.getStart().add(project);
            startLine1.updatePoints(startLine1.getStart(), line1EndPoint);
            Vector3f line2EndPoint = line1EndPoint.add(point.subtract(line1EndPoint).project(Vector3f.UNIT_Y));
            startLine2.updatePoints(line1EndPoint, line2EndPoint);
            // Vector3f line3EndPoint = point;
            startLine3.updatePoints(line2EndPoint, point);
        } else if (state == State.Mid) {
            // 计算midLine1.getStart() 与  鼠标point 向量在X与Z轴的投影。
            Vector3f tmpPoint = null;
            tmpPoint = midLine1.getStart().add(point.subtract(midLine1.getStart()).project(midAxis));
            midLine1.updatePoints(midLine1.getStart(), tmpPoint);
            midLine2.updatePoints(tmpPoint, point);
        } else if (state == State.Ending) {
        // endLine1.updatePoints(endLine1.getStart(), point);
        }
    }, hoverMapping);
    addMapping("CLICKED_ON_BOARD", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    addMapping("CANCEL_ON_CONNECTING", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    addListener((ActionListener) (name, isPressed, tpf) -> {
        if (collision == null) {
            return;
        }
        if (desktop != collision.getGeometry()) {
            return;
        }
        if ("CANCEL_ON_CONNECTING".equals(name) && isPressed) {
            if (state == State.Starting || state == State.Mid) {
                connectClean();
            }
        }
        if ("CLICKED_ON_BOARD".equals(name) && isPressed) {
            if (state == null) {
                return;
            }
            if (state == State.Starting) {
                connectStarting();
                // 设置当前接线状态为接线中
                state = State.Mid;
            } else if (state == State.Mid) {
                connectMid();
            } else if (state == State.Ending) {
            // do nothing
            }
        }
    }, "CLICKED_ON_BOARD", "CANCEL_ON_CONNECTING");
}
Also used : BitmapFont(com.jme3.font.BitmapFont) URL(java.net.URL) ElecCompDef(com.cas.circuit.vo.ElecCompDef) TypicalCase(com.cas.sim.tis.entity.TypicalCase) MouseEventAdapter(com.cas.sim.tis.app.event.MouseEventAdapter) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) Node(com.jme3.scene.Node) Future(java.util.concurrent.Future) ElecCompAction(com.cas.sim.tis.action.ElecCompAction) ElecComp(com.cas.sim.tis.entity.ElecComp) Map(java.util.Map) WireNumberControl(com.cas.sim.tis.app.control.WireNumberControl) WireProxy(com.cas.circuit.vo.archive.WireProxy) Archive(com.cas.circuit.vo.Archive) TagNameControl(com.cas.sim.tis.app.control.TagNameControl) AnalogListener(com.jme3.input.controls.AnalogListener) IContent(com.cas.sim.tis.view.control.IContent) PageController(com.cas.sim.tis.view.controller.PageController) TypicalCaseAction(com.cas.sim.tis.action.TypicalCaseAction) Set(java.util.Set) ActionListener(com.jme3.input.controls.ActionListener) CollisionResult(com.jme3.collision.CollisionResult) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Jack(com.cas.circuit.vo.Jack) Geometry(com.jme3.scene.Geometry) ControlIO(com.cas.circuit.vo.ControlIO) HintControl(com.cas.sim.tis.app.control.HintControl) Terminal(com.cas.circuit.vo.Terminal) ElecCompProxy(com.cas.circuit.vo.archive.ElecCompProxy) JmeUtil(com.cas.sim.tis.util.JmeUtil) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) TypicalCase3D(com.cas.sim.tis.view.control.imp.jme.TypicalCase3D) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger) MouseInput(com.jme3.input.MouseInput) FastMath(com.jme3.math.FastMath) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Spatial(com.jme3.scene.Spatial) Line(com.jme3.scene.shape.Line) SpringUtil(com.cas.sim.tis.util.SpringUtil) MouseEvent(com.cas.sim.tis.app.event.MouseEvent) Nonnull(javax.annotation.Nonnull) CfgConst(com.cas.circuit.CfgConst) Vector3f(com.jme3.math.Vector3f) Wire(com.cas.circuit.vo.Wire) CullHint(com.jme3.scene.Spatial.CullHint) Quaternion(com.jme3.math.Quaternion) HTTPUtils(com.cas.sim.tis.util.HTTPUtils) JaxbUtil(com.cas.sim.tis.xml.util.JaxbUtil) ModelKey(com.jme3.asset.ModelKey) ColorRGBA(com.jme3.math.ColorRGBA) StringUtils(org.springframework.util.StringUtils) BitmapText(com.jme3.font.BitmapText) MouseAxisTrigger(com.jme3.input.controls.MouseAxisTrigger) Vector3f(com.jme3.math.Vector3f) MouseButtonTrigger(com.jme3.input.controls.MouseButtonTrigger)

Aggregations

KeyTrigger (com.jme3.input.controls.KeyTrigger)14 AnalogListener (com.jme3.input.controls.AnalogListener)13 ActionListener (com.jme3.input.controls.ActionListener)11 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)6 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)6 Vector3f (com.jme3.math.Vector3f)6 DirectionalLight (com.jme3.light.DirectionalLight)5 Material (com.jme3.material.Material)4 Geometry (com.jme3.scene.Geometry)4 Node (com.jme3.scene.Node)4 ColorRGBA (com.jme3.math.ColorRGBA)3 Spatial (com.jme3.scene.Spatial)3 Box (com.jme3.scene.shape.Box)3 BitmapText (com.jme3.font.BitmapText)2 ChaseCamera (com.jme3.input.ChaseCamera)2 MouseInput (com.jme3.input.MouseInput)2 AmbientLight (com.jme3.light.AmbientLight)2 Quaternion (com.jme3.math.Quaternion)2 CfgConst (com.cas.circuit.CfgConst)1 Archive (com.cas.circuit.vo.Archive)1