com.jme3.input.controls.KeyTrigger Java Examples

The following examples show how to use com.jme3.input.controls.KeyTrigger. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WorldOfInception.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setupKeys() {
    inputManager.addMapping("StrafeLeft", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("StrafeRight", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("Forward", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Back", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("StrafeUp", new KeyTrigger(KeyInput.KEY_Q));
    inputManager.addMapping("StrafeDown", new KeyTrigger(KeyInput.KEY_Z), new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addMapping("Space", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("Return", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("Esc", new KeyTrigger(KeyInput.KEY_ESCAPE));
    inputManager.addMapping("Up", new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("Down", new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Left", new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Right", new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addListener(this, "StrafeLeft", "StrafeRight", "Forward", "Back", "StrafeUp", "StrafeDown", "Space", "Reset", "Esc", "Up", "Down", "Left", "Right");
}
 
Example #2
Source File: TestJaime.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void setupInput() {
    inputManager.addMapping("start", new KeyTrigger(KeyInput.KEY_PAUSE));
    inputManager.addListener(new ActionListener() {

        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if(name.equals("start") && isPressed){
                if(cinematic.getPlayState() != PlayState.Playing){                                                
                    cinematic.play();
                }else{
                    cinematic.pause();
                }
            }
        }
    }, "start");
}
 
Example #3
Source File: TerrainTestCollision.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setupKeys() {
    flyCam.setMoveSpeed(50);
    inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(actionListener, "wireframe");
    inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("Forwards", new KeyTrigger(KeyInput.KEY_Y));
    inputManager.addMapping("Backs", new KeyTrigger(KeyInput.KEY_I));
    inputManager.addListener(actionListener, "Lefts");
    inputManager.addListener(actionListener, "Rights");
    inputManager.addListener(actionListener, "Ups");
    inputManager.addListener(actionListener, "Downs");
    inputManager.addListener(actionListener, "Forwards");
    inputManager.addListener(actionListener, "Backs");
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    inputManager.addMapping("cameraDown", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addListener(actionListener, "cameraDown");
}
 
Example #4
Source File: TestAnisotropicFilter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    maxAniso = renderer.getLimits().get(Limits.TextureAnisotropy);

    flyCam.setDragToRotate(true);
    flyCam.setMoveSpeed(100);
    cam.setLocation(new Vector3f(197.02617f, 4.6769195f, -194.89545f));
    cam.setRotation(new Quaternion(0.07921988f, 0.8992258f, -0.18292196f, 0.38943136f));
    Quad q = new Quad(1000, 1000);
    q.scaleTextureCoordinates(new Vector2f(1000, 1000));
    Geometry geom = new Geometry("quad", q);
    geom.rotate(-FastMath.HALF_PI, 0, 0);
    geom.setMaterial(createCheckerBoardMaterial(assetManager));
    rootNode.attachChild(geom);

    inputManager.addMapping("higher", new KeyTrigger(KeyInput.KEY_1));
    inputManager.addMapping("lower", new KeyTrigger(KeyInput.KEY_2));
    inputManager.addListener(this, "higher");
    inputManager.addListener(this, "lower");
}
 
Example #5
Source File: TestBitmapFont.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    inputManager.addMapping("WordWrap", new KeyTrigger(KeyInput.KEY_TAB));
    inputManager.addListener(keyListener, "WordWrap");
    inputManager.addRawInputListener(textListener);

    BitmapFont fnt = assetManager.loadFont("Interface/Fonts/Default.fnt");
    txt = new BitmapText(fnt, false);
    txt.setBox(new Rectangle(0, 0, settings.getWidth(), settings.getHeight()));
    txt.setSize(fnt.getPreferredSize() * 2f);
    txt.setText(txtB);
    txt.setLocalTranslation(0, txt.getHeight(), 0);
    guiNode.attachChild(txt);

    txt2 = new BitmapText(fnt, false);
    txt2.setSize(fnt.getPreferredSize() * 1.2f);
    txt2.setText("Text without restriction. \nText without restriction. Text without restriction. Text without restriction");
    txt2.setLocalTranslation(0, txt2.getHeight(), 0);
    guiNode.attachChild(txt2);

    txt3 = new BitmapText(fnt, false);
    txt3.setBox(new Rectangle(0, 0, settings.getWidth(), 0));
    txt3.setText("Press Tab to toggle word-wrap. type text and enter to input text");
    txt3.setLocalTranslation(0, settings.getHeight()/2, 0);
    guiNode.attachChild(txt3);
}
 
Example #6
Source File: TestBitmapFontLayout.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void setupUserInput() {

        inputManager.addMapping(SCROLL_UP, new KeyTrigger(KeyInput.KEY_UP),
                                           new KeyTrigger(KeyInput.KEY_W));
        inputManager.addMapping(SCROLL_DOWN, new KeyTrigger(KeyInput.KEY_DOWN),
                                           new KeyTrigger(KeyInput.KEY_S));
        inputManager.addMapping(SCROLL_LEFT, new KeyTrigger(KeyInput.KEY_LEFT),
                                           new KeyTrigger(KeyInput.KEY_A));
        inputManager.addMapping(SCROLL_RIGHT, new KeyTrigger(KeyInput.KEY_RIGHT),
                                           new KeyTrigger(KeyInput.KEY_D));
        inputManager.addMapping(ZOOM_IN, new KeyTrigger(KeyInput.KEY_ADD), 
                                         new KeyTrigger(KeyInput.KEY_EQUALS),
                                         new KeyTrigger(KeyInput.KEY_Q));
        inputManager.addMapping(ZOOM_OUT, new KeyTrigger(KeyInput.KEY_MINUS),
                                         new KeyTrigger(KeyInput.KEY_SUBTRACT),
                                         new KeyTrigger(KeyInput.KEY_Z));
        inputManager.addMapping(RESET_VIEW, new KeyTrigger(KeyInput.KEY_SPACE));
        inputManager.addMapping(RESET_ZOOM, new KeyTrigger(KeyInput.KEY_0));

        inputManager.addListener(new KeyStateListener(), 
                                 RESET_VIEW, RESET_ZOOM,
                                 SCROLL_UP, SCROLL_DOWN, SCROLL_LEFT, SCROLL_RIGHT,
                                 ZOOM_IN, ZOOM_OUT);            
    }
 
Example #7
Source File: PbrSceneTest.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
public void simpleInitApp() {
    super.simpleInitApp();
    SceneLoader.install(this, postProcessor);
    rootNode.attachChild(assetManager.loadModel("Scene/TestPbrScene.j3s"));
    getFlyByCamera().setMoveSpeed(5);
    getInputManager().addMapping("mouse", new KeyTrigger(KeyInput.KEY_SPACE));
    getInputManager().addListener(new ActionListener() {
        @Override
        public void onAction(final String name, final boolean isPressed, final float tpf) {
            if (isPressed) {
                getFlyByCamera().setEnabled(!getFlyByCamera().isEnabled());
            }
        }
    }, "mouse");
}
 
Example #8
Source File: TestIssue1283.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Configure the InputManager during startup.
 */
private void configureInputs() {
    final String launchActionName = "launch";
    ActionListener actionListener = new ActionListener() {
        @Override
        public void onAction(String name, boolean ongoing, float tpf) {
            if (ongoing) {
                if (name.equals(launchActionName)) {
                    launchProjectile();
                }
            }
        }
    };

    Trigger bTrigger = new KeyTrigger(KeyInput.KEY_B);
    Trigger rmbTrigger = new MouseButtonTrigger(MouseInput.BUTTON_RIGHT);
    inputManager.addMapping(launchActionName, bTrigger, rmbTrigger);
    inputManager.addListener(actionListener, launchActionName);
}
 
Example #9
Source File: TestSimpleWater.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
protected void initInput() {
    flyCam.setMoveSpeed(3);
    //init input
    inputManager.addMapping("use_water", new KeyTrigger(KeyInput.KEY_O));
    inputManager.addListener(this, "use_water");
    inputManager.addMapping("lightup", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(this, "lightup");
    inputManager.addMapping("lightdown", new KeyTrigger(KeyInput.KEY_G));
    inputManager.addListener(this, "lightdown");
    inputManager.addMapping("lightleft", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addListener(this, "lightleft");
    inputManager.addMapping("lightright", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addListener(this, "lightright");
    inputManager.addMapping("lightforward", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addListener(this, "lightforward");
    inputManager.addMapping("lightback", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addListener(this, "lightback");
}
 
Example #10
Source File: ScreenshotAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void initialize(AppStateManager stateManager, Application app) {
    if (!super.isInitialized()){
        InputManager inputManager = app.getInputManager();
        inputManager.addMapping("ScreenShot", new KeyTrigger(KeyInput.KEY_SYSRQ));
        inputManager.addListener(this, "ScreenShot");

        List<ViewPort> vps = app.getRenderManager().getPostViews();
        ViewPort last = vps.get(vps.size()-1);
        last.addProcessor(this);

        if (shotName == null) {
            shotName = app.getClass().getSimpleName();
        }
    }

    super.initialize(stateManager, app);
}
 
Example #11
Source File: TestWalkingChar.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setupKeys() {
    inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(this, "wireframe");
    inputManager.addMapping("CharLeft", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("CharRight", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("CharUp", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("CharDown", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("CharSpace", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("CharShoot", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(this, "CharLeft");
    inputManager.addListener(this, "CharRight");
    inputManager.addListener(this, "CharUp");
    inputManager.addListener(this, "CharDown");
    inputManager.addListener(this, "CharSpace");
    inputManager.addListener(this, "CharShoot");
}
 
Example #12
Source File: TestParallelProjection.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    Geometry teaGeom = (Geometry) assetManager.loadModel("Models/Teapot/Teapot.obj");

    DirectionalLight dl = new DirectionalLight();
    dl.setColor(ColorRGBA.White);
    dl.setDirection(Vector3f.UNIT_XYZ.negate());

    rootNode.addLight(dl);
    rootNode.attachChild(teaGeom);

    // Setup first view
    cam.setParallelProjection(true);
    float aspect = (float) cam.getWidth() / cam.getHeight();
    cam.setFrustum(-1000, 1000, -aspect * frustumSize, aspect * frustumSize, frustumSize, -frustumSize);

    inputManager.addListener(this, "Size+", "Size-");
    inputManager.addMapping("Size+", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Size-", new KeyTrigger(KeyInput.KEY_S));
}
 
Example #13
Source File: TestRagdollCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void setupKeys() {
    inputManager.addMapping("Rotate Left",
            new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("Rotate Right",
            new KeyTrigger(KeyInput.KEY_K));
    inputManager.addMapping("Walk Backward",
            new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("Walk Forward",
            new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("Slice",
            new KeyTrigger(KeyInput.KEY_SPACE),
            new KeyTrigger(KeyInput.KEY_RETURN));

    inputManager.addListener(this, "Rotate Left", "Rotate Right", "Slice",
            "Walk Backward", "Walk Forward");
}
 
Example #14
Source File: TestPosterization.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void initInputs() {
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
 
    ActionListener acl = new ActionListener() {

        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                pf.setEnabled(!pf.isEnabled());
            }
        }
    };
         
    inputManager.addListener(acl, "toggle");

}
 
Example #15
Source File: TestBloom.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void initInputs() {
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
 
    ActionListener acl = new ActionListener() {

        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if(active){
                    active=false;
                    viewPort.removeProcessor(fpp);
                }else{
                    active=true;
                    viewPort.addProcessor(fpp);
                }
            }
        }
    };
         
    inputManager.addListener(acl, "toggle");

}
 
Example #16
Source File: TestRenderToTexture.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    cam.setLocation(new Vector3f(3, 3, 3));
    cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_Y);

    //setup main scene
    Geometry quad = new Geometry("box", new Box(1, 1, 1));

    Texture offTex = setupOffscreenView();

    Material mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setTexture("ColorMap", offTex);
    quad.setMaterial(mat);
    rootNode.attachChild(quad);
    inputManager.addMapping(TOGGLE_UPDATE, new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(this, TOGGLE_UPDATE);
}
 
Example #17
Source File: TestCrossHatch.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void initInputs() {
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));
 
    ActionListener acl = new ActionListener() {

        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            if (name.equals("toggle") && keyPressed) {
                if(active){
                    active=false;
                    viewPort.removeProcessor(fpp);
                }else{
                    active=true;
                    viewPort.addProcessor(fpp);
                }
            }
        }
    };
         
    inputManager.addListener(acl, "toggle");

}
 
Example #18
Source File: DebugKeysAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void initialize(AppStateManager stateManager, Application app) {
    super.initialize(stateManager, app);
    
    this.app = app;
    this.inputManager = app.getInputManager();
    
    if (app.getInputManager() != null) {
 
        inputManager.addMapping(INPUT_MAPPING_CAMERA_POS, new KeyTrigger(KeyInput.KEY_C));
        inputManager.addMapping(INPUT_MAPPING_MEMORY, new KeyTrigger(KeyInput.KEY_M));
        
        inputManager.addListener(keyListener, 
                                 INPUT_MAPPING_CAMERA_POS, 
                                 INPUT_MAPPING_MEMORY);                   
    }               
}
 
Example #19
Source File: TestChaseCamera.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void registerInput() {
  inputManager.addMapping("moveForward", new KeyTrigger(keyInput.KEY_UP), new KeyTrigger(keyInput.KEY_W));
  inputManager.addMapping("moveBackward", new KeyTrigger(keyInput.KEY_DOWN), new KeyTrigger(keyInput.KEY_S));
  inputManager.addMapping("moveRight", new KeyTrigger(keyInput.KEY_RIGHT), new KeyTrigger(keyInput.KEY_D));
  inputManager.addMapping("moveLeft", new KeyTrigger(keyInput.KEY_LEFT), new KeyTrigger(keyInput.KEY_A));
  inputManager.addMapping("displayPosition", new KeyTrigger(keyInput.KEY_P));
  inputManager.addListener(this, "moveForward", "moveBackward", "moveRight", "moveLeft");
  inputManager.addListener(this, "displayPosition");
}
 
Example #20
Source File: TestAttachDriver.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupKeys() {
    inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_K));
    inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_J));
    inputManager.addMapping("Space", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("Reset", new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addListener(this, "Lefts");
    inputManager.addListener(this, "Rights");
    inputManager.addListener(this, "Ups");
    inputManager.addListener(this, "Downs");
    inputManager.addListener(this, "Space");
    inputManager.addListener(this, "Reset");
}
 
Example #21
Source File: TestBrickWall.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
    stateManager.attach(bulletAppState);

    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);
    brick = new Box(bLength, bHeight, bWidth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));

    initMaterial();
    initWall();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 6f, 6f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(15);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    inputManager.addMapping("gc", new KeyTrigger(KeyInput.KEY_X));
    inputManager.addListener(actionListener, "gc");

    rootNode.setShadowMode(ShadowMode.Off);
}
 
Example #22
Source File: TestQ3.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupKeys() {
    inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping("Space", new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addListener(this,"Lefts");
    inputManager.addListener(this,"Rights");
    inputManager.addListener(this,"Ups");
    inputManager.addListener(this,"Downs");
    inputManager.addListener(this,"Space");
}
 
Example #23
Source File: TestBetterCharacter.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupKeys() {
    inputManager.addMapping("Strafe Left",
            new KeyTrigger(KeyInput.KEY_U),
            new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addMapping("Strafe Right",
            new KeyTrigger(KeyInput.KEY_O),
            new KeyTrigger(KeyInput.KEY_X));
    inputManager.addMapping("Rotate Left",
            new KeyTrigger(KeyInput.KEY_J),
            new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Rotate Right",
            new KeyTrigger(KeyInput.KEY_L),
            new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("Walk Forward",
            new KeyTrigger(KeyInput.KEY_I),
            new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("Walk Backward",
            new KeyTrigger(KeyInput.KEY_K),
            new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Jump",
            new KeyTrigger(KeyInput.KEY_F),
            new KeyTrigger(KeyInput.KEY_SPACE));
    inputManager.addMapping("Duck",
            new KeyTrigger(KeyInput.KEY_G),
            new KeyTrigger(KeyInput.KEY_LSHIFT),
            new KeyTrigger(KeyInput.KEY_RSHIFT));
    inputManager.addMapping("Lock View",
            new KeyTrigger(KeyInput.KEY_RETURN));
    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", "Duck", "Lock View");
}
 
Example #24
Source File: TestOgreAnim.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4013605f, 7.488437f, 12.843031f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    Spatial model = assetManager.loadModel("Models/Oto/Oto.mesh.xml");
    model.center();

    animComposer = model.getControl(AnimComposer.class);
    animComposer.actionBlended("Attack", new LinearBlendSpace(0f, 0.5f), "Dodge");
    for (AnimClip animClip : animComposer.getAnimClips()) {
        Action action = animComposer.action(animClip.getName());
        if(!"stand".equals(animClip.getName())) {
            action = new BaseAction(Tweens.sequence(action, Tweens.callMethod(this, "backToStand", animComposer)));
        }
        animComposer.addAction(animClip.getName(), action);
    }
    currentAction = animComposer.setCurrentAction("stand"); // Walk, pull, Dodge, stand, push

    SkinningControl skinningControl = model.getControl(SkinningControl.class);
    skinningControl.setHardwareSkinningPreferred(false);

    Box b = new Box(.25f, 3f, .25f);
    Geometry item = new Geometry("Item", b);
    item.move(0, 1.5f, 0);
    item.setMaterial(assetManager.loadMaterial("Common/Materials/RedColor.j3m"));
    Node n = skinningControl.getAttachmentsNode("hand.right");
    n.attachChild(item);

    rootNode.attachChild(model);

    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #25
Source File: TestAttachmentsNode.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    cam.setLocation(new Vector3f(6.4f, 7.5f, 12.8f));
    cam.setRotation(new Quaternion(-0.060740203f, 0.93925786f, -0.2398315f, -0.2378785f));

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(ColorRGBA.White);
    rootNode.addLight(dl);

    Spatial model = assetManager.loadModel("Models/Jaime/Jaime.j3o");
    control = model.getControl(AnimControl.class);
    SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);

    model.center();
    model.setLocalScale(5f);

    control.addListener(this);
    channel = control.createChannel();
    channel.setAnim("Idle");

    Box box = new Box(0.3f, 0.02f, 0.02f);
    Geometry saber = new Geometry("saber", box);
    saber.move(0.4f, 0.05f, 0.01f);
    Material red = assetManager.loadMaterial("Common/Materials/RedColor.j3m");
    saber.setMaterial(red);
    Node n = skeletonControl.getAttachmentsNode("hand.R");
    n.attachChild(saber);
    rootNode.attachChild(model);

    inputManager.addListener(this, "Attack");
    inputManager.addMapping("Attack", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #26
Source File: TestHWSkinningOld.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    flyCam.setDragToRotate(true);
    setPauseOnLostFocus(false);
    cam.setLocation(new Vector3f(24.746134f, 13.081396f, 32.72753f));
    cam.setRotation(new Quaternion(-0.06867662f, 0.92435044f, -0.19981281f, -0.31770203f));
    makeHudText();

    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            Spatial model = assetManager.loadModel("Models/Oto/OtoOldAnim.j3o");
            model.setLocalScale(0.1f);
            model.setLocalTranslation(i - SIZE / 2, 0, j - SIZE / 2);
            control = model.getControl(AnimControl.class);

            channel = control.createChannel();
            channel.setAnim(animNames[(i + j) % 4]);
            SkeletonControl skeletonControl = model.getControl(SkeletonControl.class);
            skeletonControl.setHardwareSkinningPreferred(hwSkinningEnable);
            skControls.add(skeletonControl);
            rootNode.attachChild(model);
        }
    }

    inputManager.addListener(this, "toggleHWS");
    inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));
}
 
Example #27
Source File: TestHWSkinning.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setMoveSpeed(10f);
    flyCam.setDragToRotate(true);
    setPauseOnLostFocus(false);
    cam.setLocation(new Vector3f(38.76639f, 14.744472f, 45.097454f));
    cam.setRotation(new Quaternion(-0.06086266f, 0.92303723f, -0.1639443f, -0.34266636f));

    makeHudText();
 
    DirectionalLight dl = new DirectionalLight();
    dl.setDirection(new Vector3f(-0.1f, -0.7f, -1).normalizeLocal());
    dl.setColor(new ColorRGBA(1f, 1f, 1f, 1.0f));
    rootNode.addLight(dl);

    Spatial models[] = new Spatial[4];
    for (int i = 0; i < 4; i++) {
        models[i] =loadModel(i);
    }

    for (int i = 0; i < SIZE; i++) {
        for (int j = 0; j < SIZE; j++) {
            Node model = (Node)models[(i + j) % 4];
            Spatial s = model.getChild(0).clone();
            model.attachChild(s);
            float x = (i - SIZE / 2) / 0.1f;
            float z = (j - SIZE / 2) / 0.1f;
            s.setLocalTranslation(x, 0, z);
        }
    }

    inputManager.addListener(this, "toggleHWS");
    inputManager.addMapping("toggleHWS", new KeyTrigger(KeyInput.KEY_SPACE));

}
 
Example #28
Source File: TestLineWidthRenderState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    setDisplayFps(false);
    setDisplayStatView(false);
    cam.setLocation(new Vector3f(5.5826545f, 3.6192513f, 8.016988f));
    cam.setRotation(new Quaternion(-0.04787097f, 0.9463123f, -0.16569641f, -0.27339742f));

    Box b = new Box(1, 1, 1);
    Geometry geom = new Geometry("Box", b);
    mat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    mat.setColor("Color", ColorRGBA.Blue);
    mat.getAdditionalRenderState().setWireframe(true);
    mat.getAdditionalRenderState().setLineWidth(2);
    geom.setMaterial(mat);
    rootNode.attachChild(geom);

    inputManager.addListener(new ActionListener() {
        @Override
        public void onAction(String name, boolean isPressed, float tpf) {
            if(name.equals("up") && isPressed){
                mat.getAdditionalRenderState().setLineWidth(mat.getAdditionalRenderState().getLineWidth() + 1);
            }
            if(name.equals("down") && isPressed){
                mat.getAdditionalRenderState().setLineWidth(Math.max(mat.getAdditionalRenderState().getLineWidth() - 1, 1));
            }
        }
    }, "up", "down");
    inputManager.addMapping("up", new KeyTrigger(KeyInput.KEY_U));
    inputManager.addMapping("down", new KeyTrigger(KeyInput.KEY_J));
}
 
Example #29
Source File: IsometricCameraManager.java    From OpenRTS with MIT License 5 votes vote down vote up
@Override
public void registerInputs(InputManager inputManager){
	inputManager.addMapping(STRAFE_NORTH, new KeyTrigger(KeyInput.KEY_UP));
	inputManager.addMapping(STRAFE_SOUTH, new KeyTrigger(KeyInput.KEY_DOWN));
	inputManager.addMapping(STRAFE_EAST, new KeyTrigger(KeyInput.KEY_RIGHT));
	inputManager.addMapping(STRAFE_WEST, new KeyTrigger(KeyInput.KEY_LEFT));
	inputManager.addMapping(ZOOM_IN, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
	inputManager.addMapping(ZOOM_OUT, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
	inputManager.addListener(this, mappings);
}
 
Example #30
Source File: TestControls.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    // Test multiple inputs per mapping
    inputManager.addMapping("My Action",
            new KeyTrigger(KeyInput.KEY_SPACE),
            new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));

    // Test multiple listeners per mapping
    inputManager.addListener(actionListener, "My Action");
    inputManager.addListener(analogListener, "My Action");
}