Search in sources :

Example 66 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 67 with ActionListener

use of com.jme3.input.controls.ActionListener 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)50 ActionListener (com.jme3.input.controls.ActionListener)44 Vector3f (com.jme3.math.Vector3f)27 MouseButtonTrigger (com.jme3.input.controls.MouseButtonTrigger)18 Geometry (com.jme3.scene.Geometry)16 DirectionalLight (com.jme3.light.DirectionalLight)15 Material (com.jme3.material.Material)14 Spatial (com.jme3.scene.Spatial)13 AnalogListener (com.jme3.input.controls.AnalogListener)11 Quaternion (com.jme3.math.Quaternion)11 FilterPostProcessor (com.jme3.post.FilterPostProcessor)10 Node (com.jme3.scene.Node)10 Sphere (com.jme3.scene.shape.Sphere)10 Box (com.jme3.scene.shape.Box)9 AmbientLight (com.jme3.light.AmbientLight)7 BitmapText (com.jme3.font.BitmapText)6 MouseAxisTrigger (com.jme3.input.controls.MouseAxisTrigger)5 ChaseCamera (com.jme3.input.ChaseCamera)4 ColorRGBA (com.jme3.math.ColorRGBA)4 Vector2f (com.jme3.math.Vector2f)4