com.jme3.input.controls.MouseButtonTrigger Java Examples

The following examples show how to use com.jme3.input.controls.MouseButtonTrigger. 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: 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 #2
Source File: TestWriteToTexture.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    initOpenCL1();
    
    tex = new Texture2D(settings.getWidth(), settings.getHeight(), 1, com.jme3.texture.Image.Format.RGBA8);
    Picture pic = new Picture("julia");
    pic.setTexture(assetManager, tex, true);
    pic.setPosition(0, 0);
    pic.setWidth(settings.getWidth());
    pic.setHeight(settings.getHeight());
    guiNode.attachChild(pic);
    
    initCounter = 0;
    
    flyCam.setEnabled(false);
    inputManager.setCursorVisible(true);
    inputManager.addMapping("right", new MouseAxisTrigger(MouseInput.AXIS_X, false));
    inputManager.addMapping("left", new MouseAxisTrigger(MouseInput.AXIS_X, true));
    inputManager.addMapping("up", new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    inputManager.addMapping("down", new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    inputManager.addMapping("drag", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(this, "right", "left", "up", "down", "drag");
    dragging = false;
}
 
Example #3
Source File: TestBrickTower.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
 //   bulletAppState.setEnabled(false);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);

    brick = new Box(brickWidth, brickHeight, brickDepth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    initMaterial();
    initTower();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 25f, 8f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(80);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    rootNode.setShadowMode(ShadowMode.Off);
}
 
Example #4
Source File: BattlefieldInputInterpreter.java    From OpenRTS with MIT License 6 votes vote down vote up
@Override
protected void registerInputs(InputManager inputManager) {
	inputManager.addMapping(SWITCH_CTRL_1, new KeyTrigger(KeyInput.KEY_F1));
	inputManager.addMapping(SWITCH_CTRL_2, new KeyTrigger(KeyInput.KEY_F2));
	inputManager.addMapping(SWITCH_CTRL_3, new KeyTrigger(KeyInput.KEY_F3));
	inputManager.addMapping(SELECT, new MouseButtonTrigger(0));
	inputManager.addMapping(ACTION, new MouseButtonTrigger(1));
	inputManager.addMapping(MOVE_ATTACK, new KeyTrigger(KeyInput.KEY_A));
	inputManager.addMapping(MULTIPLE_SELECTION, new KeyTrigger(KeyInput.KEY_LCONTROL),
			new KeyTrigger(KeyInput.KEY_RCONTROL));
	inputManager.addMapping(HOLD, new KeyTrigger(KeyInput.KEY_H));
	inputManager.addMapping(PAUSE, new KeyTrigger(KeyInput.KEY_SPACE));

	inputManager.addListener(this, mappings);

	logger.info("battlefield controller online");
}
 
Example #5
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 #6
Source File: TerrainTestCollision.java    From MikuMikuStudio with BSD 2-Clause "Simplified" 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 #7
Source File: TerrainTestModifyHeight.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setupKeys() {
    flyCam.setMoveSpeed(100);
    inputManager.addMapping("wireframe", new KeyTrigger(KeyInput.KEY_T));
    inputManager.addListener(actionListener, "wireframe");
    inputManager.addMapping("Raise", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "Raise");
    inputManager.addMapping("Lower", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addListener(actionListener, "Lower");
}
 
Example #8
Source File: TerrainGridTileLoaderTest.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void initKeys() {
    // You can map one or several inputs to one named action
    this.inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_A));
    this.inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D));
    this.inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W));
    this.inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S));
    this.inputManager.addMapping("Jumps", new KeyTrigger(KeyInput.KEY_SPACE));
    this.inputManager.addMapping("pick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    this.inputManager.addListener(this.actionListener, "Lefts");
    this.inputManager.addListener(this.actionListener, "Rights");
    this.inputManager.addListener(this.actionListener, "Ups");
    this.inputManager.addListener(this.actionListener, "Downs");
    this.inputManager.addListener(this.actionListener, "Jumps");
    this.inputManager.addListener(this.actionListener, "pick");
}
 
Example #9
Source File: PhysicsTestHelper.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * creates the necessary inputlistener and action to shoot balls from teh camera
 * @param app
 * @param rootNode
 * @param space
 */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(1);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
 
Example #10
Source File: LockableChaseCamera.java    From OpenRTS with MIT License 5 votes vote down vote up
public void unLock() {
	String[] inputs = {ChaseCamToggleRotate,
            ChaseCamDown,
            ChaseCamUp,
            ChaseCamMoveLeft,
            ChaseCamMoveRight,
            ChaseCamZoomIn,
            ChaseCamZoomOut};

        if (!invertYaxis) {
            inputManager.addMapping(ChaseCamDown, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
            inputManager.addMapping(ChaseCamUp, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
        } else {
            inputManager.addMapping(ChaseCamDown, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
            inputManager.addMapping(ChaseCamUp, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        }
        inputManager.addMapping(ChaseCamZoomIn, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
        inputManager.addMapping(ChaseCamZoomOut, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
        if(!invertXaxis){
            inputManager.addMapping(ChaseCamMoveLeft, new MouseAxisTrigger(MouseInput.AXIS_X, true));
            inputManager.addMapping(ChaseCamMoveRight, new MouseAxisTrigger(MouseInput.AXIS_X, false));
        }else{
            inputManager.addMapping(ChaseCamMoveLeft, new MouseAxisTrigger(MouseInput.AXIS_X, false));
            inputManager.addMapping(ChaseCamMoveRight, new MouseAxisTrigger(MouseInput.AXIS_X, true));
        }
        inputManager.addMapping(ChaseCamToggleRotate, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
        inputManager.addMapping(ChaseCamToggleRotate, new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));

        inputManager.addListener(this, inputs);
        
        if(!isDragToRotate())
        	inputManager.setCursorVisible(false);
        	
        
}
 
Example #11
Source File: TestBrickWall.java    From MikuMikuStudio with BSD 2-Clause "Simplified" 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(Vector3f.ZERO, 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);
    bsr = new BasicShadowRenderer(assetManager, 256);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    viewPort.addProcessor(bsr);
}
 
Example #12
Source File: TestBrickTower.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
 //   bulletAppState.setEnabled(false);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);

    brick = new Box(Vector3f.ZERO, brickWidth, brickHeight, brickDepth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    initMaterial();
    initTower();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 25f, 8f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(80);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    rootNode.setShadowMode(ShadowMode.Off);
    bsr = new PssmShadowRenderer(assetManager, 1024, 2);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    bsr.setLambda(0.55f);
    bsr.setShadowIntensity(0.6f);
    bsr.setCompareMode(CompareMode.Hardware);
    bsr.setFilterMode(FilterMode.PCF4);
    viewPort.addProcessor(bsr);
}
 
Example #13
Source File: TestRagDoll.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    inputManager.addMapping("Pull ragdoll up", new MouseButtonTrigger(0));
    inputManager.addListener(this, "Pull ragdoll up");
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    createRagDoll();
}
 
Example #14
Source File: HelloInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** 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));
  inputManager.addMapping("Rotate", new KeyTrigger(KeyInput.KEY_SPACE), // spacebar!
                                    new MouseButtonTrigger(MouseInput.BUTTON_LEFT) );        // left click!
  /** Add the named mappings to the action listeners. */
  inputManager.addListener(actionListener, new String[]{"Pause"});
  inputManager.addListener(analogListener, new String[]{"Left", "Right", "Rotate"});
}
 
Example #15
Source File: FlyByCamera.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Register this controller to receive input events from the specified input
 * manager.
 *
 * @param inputManager
 */
public void registerWithInput(InputManager inputManager){
    this.inputManager = inputManager;

    // both mouse and button - rotation of cam
    inputManager.addMapping(CameraInput.FLYCAM_LEFT, new MouseAxisTrigger(MouseInput.AXIS_X, true),
            new KeyTrigger(KeyInput.KEY_LEFT));

    inputManager.addMapping(CameraInput.FLYCAM_RIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, false),
            new KeyTrigger(KeyInput.KEY_RIGHT));

    inputManager.addMapping(CameraInput.FLYCAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, false),
            new KeyTrigger(KeyInput.KEY_UP));

    inputManager.addMapping(CameraInput.FLYCAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, true),
            new KeyTrigger(KeyInput.KEY_DOWN));

    // mouse only - zoom in/out with wheel, and rotate drag
    inputManager.addMapping(CameraInput.FLYCAM_ZOOMIN, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    inputManager.addMapping(CameraInput.FLYCAM_ZOOMOUT, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
    inputManager.addMapping(CameraInput.FLYCAM_ROTATEDRAG, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));

    // keyboard only WASD for movement and WZ for rise/lower height
    inputManager.addMapping(CameraInput.FLYCAM_STRAFELEFT, new KeyTrigger(KeyInput.KEY_A));
    inputManager.addMapping(CameraInput.FLYCAM_STRAFERIGHT, new KeyTrigger(KeyInput.KEY_D));
    inputManager.addMapping(CameraInput.FLYCAM_FORWARD, new KeyTrigger(KeyInput.KEY_W));
    inputManager.addMapping(CameraInput.FLYCAM_BACKWARD, new KeyTrigger(KeyInput.KEY_S));
    inputManager.addMapping(CameraInput.FLYCAM_RISE, new KeyTrigger(KeyInput.KEY_Q));
    inputManager.addMapping(CameraInput.FLYCAM_LOWER, new KeyTrigger(KeyInput.KEY_Z));

    inputManager.addListener(this, mappings);
    inputManager.setCursorVisible(dragToRotate || !isEnabled());

    Joystick[] joysticks = inputManager.getJoysticks();
    if (joysticks != null && joysticks.length > 0){
        for (Joystick j : joysticks) {
            mapJoystick(j);
        }
    }
}
 
Example #16
Source File: TestCameraNode.java    From MikuMikuStudio with BSD 2-Clause "Simplified" 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("toggleRotate", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
  inputManager.addMapping("rotateRight", new MouseAxisTrigger(MouseInput.AXIS_X, true));
  inputManager.addMapping("rotateLeft", new MouseAxisTrigger(MouseInput.AXIS_X, false));
  inputManager.addListener(this, "moveForward", "moveBackward", "moveRight", "moveLeft");
  inputManager.addListener(this, "rotateRight", "rotateLeft", "toggleRotate");
}
 
Example #17
Source File: TestPhysicsCharacter.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void setupKeys() {
    inputManager.addMapping("Strafe Left", 
            new KeyTrigger(KeyInput.KEY_Q), 
            new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addMapping("Strafe Right", 
            new KeyTrigger(KeyInput.KEY_E),
            new KeyTrigger(KeyInput.KEY_X));
    inputManager.addMapping("Rotate Left", 
            new KeyTrigger(KeyInput.KEY_A), 
            new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Rotate Right", 
            new KeyTrigger(KeyInput.KEY_D), 
            new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("Walk Forward", 
            new KeyTrigger(KeyInput.KEY_W), 
            new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("Walk Backward", 
            new KeyTrigger(KeyInput.KEY_S),
            new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Jump", 
            new KeyTrigger(KeyInput.KEY_SPACE), 
            new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("Shoot", 
            new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    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", "Shoot");
}
 
Example #18
Source File: TestBatchNodeTower.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    timer = new NanoTimer();
    bulletAppState = new BulletAppState();
    bulletAppState.setThreadingType(BulletAppState.ThreadingType.PARALLEL);
 //   bulletAppState.setEnabled(false);
    stateManager.attach(bulletAppState);
    bullet = new Sphere(32, 32, 0.4f, true, false);
    bullet.setTextureMode(TextureMode.Projected);
    bulletCollisionShape = new SphereCollisionShape(0.4f);

    brick = new Box(Vector3f.ZERO, brickWidth, brickHeight, brickDepth);
    brick.scaleTextureCoordinates(new Vector2f(1f, .5f));
    //bulletAppState.getPhysicsSpace().enableDebug(assetManager);
    initMaterial();
    initTower();
    initFloor();
    initCrossHairs();
    this.cam.setLocation(new Vector3f(0, 25f, 8f));
    cam.lookAt(Vector3f.ZERO, new Vector3f(0, 1, 0));
    cam.setFrustumFar(80);
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(actionListener, "shoot");
    rootNode.setShadowMode(ShadowMode.Off);
    
    batchNode.batch();
    batchNode.setShadowMode(ShadowMode.CastAndReceive);
    rootNode.attachChild(batchNode);
    
    
    bsr = new PssmShadowRenderer(assetManager, 1024, 2);
    bsr.setDirection(new Vector3f(-1, -1, -1).normalizeLocal());
    bsr.setLambda(0.55f);
    bsr.setShadowIntensity(0.6f);
    bsr.setCompareMode(CompareMode.Hardware);
    bsr.setFilterMode(FilterMode.PCF4);
    viewPort.addProcessor(bsr);   
}
 
Example #19
Source File: HelloPicking.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/** Declaring the "Shoot" action and mapping to its triggers. */
private void initKeys() {
  inputManager.addMapping("Shoot",
    new KeyTrigger(KeyInput.KEY_SPACE), // trigger 1: spacebar
    new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); // trigger 2: left-button click
  inputManager.addListener(actionListener, "Shoot");
}
 
Example #20
Source File: TestBoneRagdoll.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void setupKeys() {
    inputManager.addMapping("boom", new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    inputManager.addMapping("bullet+", new KeyTrigger(KeyInput.KEY_PERIOD));
    inputManager.addMapping("bullet-", new KeyTrigger(KeyInput.KEY_COMMA));
    inputManager.addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping("stop", new KeyTrigger(KeyInput.KEY_H));
    inputManager.addMapping("toggle", new KeyTrigger(KeyInput.KEY_SPACE));

    inputManager.addListener(this,
            "boom", "bullet-", "bullet+", "shoot", "stop", "toggle");

}
 
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: PhysicsTestHelper.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * creates the necessary inputlistener and action to shoot balls from the camera
 *
 * @param app the application that's running
 * @param rootNode where ball geometries should be added
 * @param space where collision objects should be added
 */
public static void createBallShooter(final Application app, final Node rootNode, final PhysicsSpace space) {
    ActionListener actionListener = new ActionListener() {

        @Override
        public void onAction(String name, boolean keyPressed, float tpf) {
            Sphere bullet = new Sphere(32, 32, 0.4f, true, false);
            bullet.setTextureMode(TextureMode.Projected);
            Material mat2 = new Material(app.getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md");
            TextureKey key2 = new TextureKey("Textures/Terrain/Rock/Rock.PNG");
            key2.setGenerateMips(true);
            Texture tex2 = app.getAssetManager().loadTexture(key2);
            mat2.setTexture("ColorMap", tex2);
            if (name.equals("shoot") && !keyPressed) {
                Geometry bulletg = new Geometry("bullet", bullet);
                bulletg.setMaterial(mat2);
                bulletg.setShadowMode(ShadowMode.CastAndReceive);
                bulletg.setLocalTranslation(app.getCamera().getLocation());
                RigidBodyControl bulletControl = new RigidBodyControl(10);
                bulletg.addControl(bulletControl);
                bulletControl.setLinearVelocity(app.getCamera().getDirection().mult(25));
                bulletg.addControl(bulletControl);
                rootNode.attachChild(bulletg);
                space.add(bulletControl);
            }
        }
    };
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    app.getInputManager().addListener(actionListener, "shoot");
}
 
Example #23
Source File: TestRagDoll.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    bulletAppState = new BulletAppState();
    stateManager.attach(bulletAppState);
    bulletAppState.setDebugEnabled(true);
    inputManager.addMapping("Pull ragdoll up", new MouseButtonTrigger(0));
    inputManager.addListener(this, "Pull ragdoll up");
    PhysicsTestHelper.createPhysicsTestWorld(rootNode, assetManager, bulletAppState.getPhysicsSpace());
    createRagDoll();
}
 
Example #24
Source File: TestPhysicsCharacter.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_Q), 
            new KeyTrigger(KeyInput.KEY_Z));
    inputManager.addMapping("Strafe Right", 
            new KeyTrigger(KeyInput.KEY_E),
            new KeyTrigger(KeyInput.KEY_X));
    inputManager.addMapping("Rotate Left", 
            new KeyTrigger(KeyInput.KEY_A), 
            new KeyTrigger(KeyInput.KEY_LEFT));
    inputManager.addMapping("Rotate Right", 
            new KeyTrigger(KeyInput.KEY_D), 
            new KeyTrigger(KeyInput.KEY_RIGHT));
    inputManager.addMapping("Walk Forward", 
            new KeyTrigger(KeyInput.KEY_W), 
            new KeyTrigger(KeyInput.KEY_UP));
    inputManager.addMapping("Walk Backward", 
            new KeyTrigger(KeyInput.KEY_S),
            new KeyTrigger(KeyInput.KEY_DOWN));
    inputManager.addMapping("Jump", 
            new KeyTrigger(KeyInput.KEY_SPACE), 
            new KeyTrigger(KeyInput.KEY_RETURN));
    inputManager.addMapping("Shoot", 
            new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    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", "Shoot");
}
 
Example #25
Source File: ChaseCamera.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Registers inputs with the input manager
 * @param inputManager
 */
public final void registerWithInput(InputManager inputManager) {

    String[] inputs = {ChaseCamToggleRotate,
        ChaseCamDown,
        ChaseCamUp,
        ChaseCamMoveLeft,
        ChaseCamMoveRight,
        ChaseCamZoomIn,
        ChaseCamZoomOut};

    this.inputManager = inputManager;
    if (!invertYaxis) {
        inputManager.addMapping(ChaseCamDown, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        inputManager.addMapping(ChaseCamUp, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    } else {
        inputManager.addMapping(ChaseCamDown, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
        inputManager.addMapping(ChaseCamUp, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    }
    inputManager.addMapping(ChaseCamZoomIn, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    inputManager.addMapping(ChaseCamZoomOut, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
    if(!invertXaxis){
        inputManager.addMapping(ChaseCamMoveLeft, new MouseAxisTrigger(MouseInput.AXIS_X, true));
        inputManager.addMapping(ChaseCamMoveRight, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    }else{
        inputManager.addMapping(ChaseCamMoveLeft, new MouseAxisTrigger(MouseInput.AXIS_X, false));
        inputManager.addMapping(ChaseCamMoveRight, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    }
    inputManager.addMapping(ChaseCamToggleRotate, new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addMapping(ChaseCamToggleRotate, new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));

    inputManager.addListener(this, inputs);
}
 
Example #26
Source File: TestSplitScreen.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void simpleInitApp() {
    flyCam.setEnabled(false);

    Geometry blueBox = new Geometry("blue box", mesh);
    Material blueMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    blueMat.setColor("Color", ColorRGBA.Blue);
    blueBox.setMaterial(blueMat);
    rootNode.attachChild(blueBox);

    rightCam = cam.clone();
    rightCam.setViewPort(0.5f, 1f, 0f, 1f);

    rightView = renderManager.createMainView("right", rightCam);
    rightView.setClearFlags(true, true, true);
    rightView.setEnabled(false);
    rightView.attachScene(rootNode);

    Geometry redBox = new Geometry("red box", mesh);
    Material redMat = new Material(assetManager, "Common/MatDefs/Misc/Unshaded.j3md");
    redMat.setColor("Color", ColorRGBA.Red);
    redBox.setMaterial(redMat);
    leftScene.attachChild(redBox);

    leftCam = cam.clone();
    leftCam.setViewPort(0f, 0.5f, 0f, 1f);

    leftView = renderManager.createMainView("left", leftCam);
    leftView.setClearFlags(true, true, true);
    leftView.setEnabled(false);
    leftView.attachScene(leftScene);

    inputManager.addMapping("lmb", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    inputManager.addListener(this, "lmb");
}
 
Example #27
Source File: HelloPicking.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** Declaring the "Shoot" action and mapping to its triggers. */
private void initKeys() {
  inputManager.addMapping("Shoot",
    new KeyTrigger(KeyInput.KEY_SPACE), // trigger 1: spacebar
    new MouseButtonTrigger(MouseInput.BUTTON_LEFT)); // trigger 2: left-button click
  inputManager.addListener(actionListener, "Shoot");
}
 
Example #28
Source File: HelloInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/** 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));
  inputManager.addMapping("Rotate", new KeyTrigger(KeyInput.KEY_SPACE), // spacebar!
                                    new MouseButtonTrigger(MouseInput.BUTTON_LEFT) );        // left click!
  /** Add the named mappings to the action listeners. */
  inputManager.addListener(actionListener,"Pause");
  inputManager.addListener(analogListener,"Left", "Right", "Rotate");
}
 
Example #29
Source File: EditorCamera.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Registers inputs with the input manager
 *
 * @param inputManager the input manager
 */
public final void registerInput(final InputManager inputManager) {
    this.inputManager = inputManager;

    if (!inputManager.hasMapping(CHASECAM_DOWN)) {
        inputManager.addMapping(CHASECAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    }

    if (!inputManager.hasMapping(CHASECAM_UP)) {
        inputManager.addMapping(CHASECAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    }

    if (!inputManager.hasMapping(CHASECAM_ZOOMIN)) {
        inputManager.addMapping(CHASECAM_ZOOMIN, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, false));
    }

    if (!inputManager.hasMapping(CHASECAM_ZOOMOUT)) {
        inputManager.addMapping(CHASECAM_ZOOMOUT, new MouseAxisTrigger(MouseInput.AXIS_WHEEL, true));
    }

    if (!inputManager.hasMapping(CHASECAM_MOVELEFT)) {
        inputManager.addMapping(CHASECAM_MOVELEFT, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    }

    if (!inputManager.hasMapping(CHASECAM_MOVERIGHT)) {
        inputManager.addMapping(CHASECAM_MOVERIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    }

    if (!inputManager.hasMapping(CHASECAM_TOGGLEROTATE)) {
        inputManager.addMapping(CHASECAM_TOGGLEROTATE, new MouseButtonTrigger(MouseInput.BUTTON_MIDDLE));
    }

    inputManager.addListener(this, ALL_INPUTS);
}
 
Example #30
Source File: TerrainGridTileLoaderTest.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initKeys() {
    // You can map one or several inputs to one named action
    this.inputManager.addMapping("Lefts", new KeyTrigger(KeyInput.KEY_A));
    this.inputManager.addMapping("Rights", new KeyTrigger(KeyInput.KEY_D));
    this.inputManager.addMapping("Ups", new KeyTrigger(KeyInput.KEY_W));
    this.inputManager.addMapping("Downs", new KeyTrigger(KeyInput.KEY_S));
    this.inputManager.addMapping("Jumps", new KeyTrigger(KeyInput.KEY_SPACE));
    this.inputManager.addMapping("pick", new MouseButtonTrigger(MouseInput.BUTTON_LEFT));
    this.inputManager.addListener(this.actionListener, "Lefts");
    this.inputManager.addListener(this.actionListener, "Rights");
    this.inputManager.addListener(this.actionListener, "Ups");
    this.inputManager.addListener(this.actionListener, "Downs");
    this.inputManager.addListener(this.actionListener, "Jumps");
    this.inputManager.addListener(this.actionListener, "pick");
}