com.jme3.input.MouseInput Java Examples

The following examples show how to use com.jme3.input.MouseInput. 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: Slider.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void cursorButtonEvent( CursorButtonEvent event, Spatial target, Spatial capture ) {
    if( event.getButtonIndex() != MouseInput.BUTTON_LEFT )
        return;

    //if( capture != null && capture != target )
    //    return;

    event.setConsumed();
    if( event.isPressed() ) {
        drag = new Vector2f(event.getX(), event.getY());
        startPercent = model.getPercent();
    } else {
        // Dragging is done.
        drag = null;
    }
}
 
Example #2
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 #3
Source File: AwtMouseInput.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 6 votes vote down vote up
private int getJMEButtonIndex( MouseEvent arg0 ) {
    int index;
    switch (arg0.getButton()) {
        default:
        case MouseEvent.BUTTON1: //left
            index = MouseInput.BUTTON_LEFT;
            break;
        case MouseEvent.BUTTON2: //middle
            index = MouseInput.BUTTON_MIDDLE;
            break;
        case MouseEvent.BUTTON3: //right
            index = MouseInput.BUTTON_RIGHT;
            break;
    }
    return index;
}
 
Example #4
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 #5
Source File: GroundCameraManager.java    From OpenRTS with MIT License 6 votes vote down vote up
@Override
public void registerInputs(InputManager inputManager){
	inputManager.addMapping(ROTATE_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
	inputManager.addMapping(ROTATE_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
	inputManager.addMapping(ROTATE_LEFT, new MouseAxisTrigger(MouseInput.AXIS_X, true));
	inputManager.addMapping(ROTATE_RIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, false));

	inputManager.addMapping(STRAFE_LEFT, new KeyTrigger(KeyInput.KEY_Q),
			new KeyTrigger(KeyInput.KEY_LEFT));
	inputManager.addMapping(STRAFE_RIGHT, new KeyTrigger(KeyInput.KEY_D),
			new KeyTrigger(KeyInput.KEY_RIGHT));
	inputManager.addMapping(MOVE_FOREWARD, new KeyTrigger(KeyInput.KEY_Z),
			new KeyTrigger(KeyInput.KEY_UP));
	inputManager.addMapping(MOVE_BACKWARD, new KeyTrigger(KeyInput.KEY_S),
			new KeyTrigger(KeyInput.KEY_DOWN));
	inputManager.addListener(this, mappings);
}
 
Example #6
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 #7
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 #8
Source File: ArmatureDebugAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void initialize(Application app) {
    vp = app.getRenderManager().createMainView("debug", app.getCamera());
    vp.attachScene(debugNode);
    vp.setClearDepth(true);
    this.app = app;
    for (ArmatureDebugger armatureDebugger : armatures.values()) {
        armatureDebugger.initialize(app.getAssetManager(), app.getCamera());
    }
    app.getInputManager().addListener(actionListener, "shoot", "toggleJoints");
    app.getInputManager().addMapping("shoot", new MouseButtonTrigger(MouseInput.BUTTON_LEFT), new MouseButtonTrigger(MouseInput.BUTTON_RIGHT));
    app.getInputManager().addMapping("toggleJoints", new KeyTrigger(KeyInput.KEY_F10));

    debugNode.addLight(new DirectionalLight(new Vector3f(-1f, -1f, -1f).normalizeLocal()));

    debugNode.addLight(new DirectionalLight(new Vector3f(1f, 1f, 1f).normalizeLocal(), new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f)));
    vp.setEnabled(false);
}
 
Example #9
Source File: AbstractVRMouseManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void initialize() {
	
	logger.config("Initializing VR mouse manager.");
	
    // load default mouseimage
    mouseImage = new Picture("mouse");
    setImage("Common/Util/mouse.png");
    // hide default cursor by making it invisible
    
    MouseInput mi = environment.getApplication().getContext().getMouseInput();
    if( mi instanceof GlfwMouseInputVR ){       	
    	((GlfwMouseInputVR)mi).hideActiveCursor();
    }
    centerMouse();
    
    logger.config("Initialized VR mouse manager [SUCCESS]");
}
 
Example #10
Source File: AbstractVRMouseManager.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void centerMouse() {
	
	if (environment != null){
		if (environment.getApplication() != null){
	        // set mouse in center of the screen if newly added
	        Vector2f size = environment.getVRGUIManager().getCanvasSize();
	        MouseInput mi = environment.getApplication().getContext().getMouseInput();
	        AppSettings as = environment.getApplication().getContext().getSettings();
	        if( mi instanceof GlfwMouseInputVR ) ((GlfwMouseInputVR)mi).setCursorPosition((int)(as.getWidth() / 2f), (int)(as.getHeight() / 2f));
	        if( environment.isInVR() ) {
	            cursorPos.x = size.x / 2f;
	            cursorPos.y = size.y / 2f;
	            recentCenterCount = 2;
	        }
		} else {
			throw new IllegalStateException("This VR environment is not attached to any application.");
		}
	} else {
        throw new IllegalStateException("This VR view manager is not attached to any VR environment.");
  	} 
	
}
 
Example #11
Source File: AwtMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private int getJMEButtonIndex(MouseEvent awtEvt) {
    int index;
    switch (awtEvt.getButton()) {
        default:
        case MouseEvent.BUTTON1: //left
            index = MouseInput.BUTTON_LEFT;
            break;
        case MouseEvent.BUTTON2: //middle
            index = MouseInput.BUTTON_MIDDLE;
            break;
        case MouseEvent.BUTTON3: //right
            index = MouseInput.BUTTON_RIGHT;
            break;
    }
    return index;
}
 
Example #12
Source File: TouchAppState.java    From Lemur with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Dispatches a button action to the appropriate PickEventSession for the
 * touch pointer provided.
 * @param pointerData  PointerData object for the appropriate touch pointer
 * @param pressed  True when pressed, False when released
 * @return  True if the PickEventSession consumed the event, False otherwise.
 */
protected boolean dispatchButton(PointerData pointerData, boolean pressed) {
    // We are passing BUTTON_LEFT to buttonEvent all the time.
    // This is ok because touch motion is separated by individual
    // targetSesstions for each finger.  Since each session only gets the
    // touch motion for the finger that is associated with the session,
    // it's ok to not track the touch pointerId inside each session.
    boolean buttonConsumed = pointerData.session.buttonEvent(
            MouseInput.BUTTON_LEFT, pointerData.lastX, pointerData.lastY, pressed);
    if (buttonConsumed && !pressed) {
        // For the UP event, clear the hitTarget so mouseExited will be
        // called.  This is necessary because for touch there are no additional
        // mouse motions after the UP to cause mouseExited to be called.
        pointerData.session.clearHitTarget();
    }
    return buttonConsumed;
}
 
Example #13
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 #14
Source File: GlfwMouseInput.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Simply converts the GLFW button code to a JME button code. If there is no
 * match it just returns the GLFW button code. Bear in mind GLFW supports 8
 * different mouse buttons.
 *
 * @param glfwButton the raw GLFW button index.
 * @return the mapped {@link MouseInput} button id.
 */
private int convertButton(final int glfwButton) {
    switch (glfwButton) {
        case GLFW_MOUSE_BUTTON_LEFT:
            return MouseInput.BUTTON_LEFT;
        case GLFW_MOUSE_BUTTON_MIDDLE:
            return MouseInput.BUTTON_MIDDLE;
        case GLFW_MOUSE_BUTTON_RIGHT:
            return MouseInput.BUTTON_RIGHT;
        default:
            return glfwButton;
    }
}
 
Example #15
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 #16
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 #17
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 #18
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 #19
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 #20
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 #21
Source File: TestControls.java    From MikuMikuStudio with BSD 2-Clause "Simplified" 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");
}
 
Example #22
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 #23
Source File: MouseAxisTrigger.java    From MikuMikuStudio with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public String getName() {
    String sign = negative ? "Negative" : "Positive";
    switch (mouseAxis){
        case MouseInput.AXIS_X: return "Mouse X Axis " + sign;
        case MouseInput.AXIS_Y: return "Mouse Y Axis " + sign;
        case MouseInput.AXIS_WHEEL: return "Mouse Wheel " + sign;
        default: throw new AssertionError();
    }
}
 
Example #24
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 #25
Source File: DragHandler.java    From Lemur with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public void cursorButtonEvent( CursorButtonEvent event, Spatial target, Spatial capture ) {
    if( event.getButtonIndex() != MouseInput.BUTTON_LEFT )
        return;

    if( event.isPressed() ) {
        startDrag(event, target, capture);
    } else {
        // Dragging is done.
        // Only delegate the up events if we were dragging in the first place.
        if( drag != null ) {
            endDrag(event, target, capture);
        }
    }
}
 
Example #26
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 #27
Source File: MouseAxisTrigger.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public String getName() {
    String sign = negative ? "Negative" : "Positive";
    switch (mouseAxis){
        case MouseInput.AXIS_X: return "Mouse X Axis " + sign;
        case MouseInput.AXIS_Y: return "Mouse Y Axis " + sign;
        case MouseInput.AXIS_WHEEL: return "Mouse Wheel " + sign;
        default: throw new AssertionError();
    }
}
 
Example #28
Source File: ChaseCameraAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initHorizontalAxisInput() {
    if (!invertXaxis) {
        inputManager.addMapping(CameraInput.CHASECAM_MOVELEFT, new MouseAxisTrigger(MouseInput.AXIS_X, true));
        inputManager.addMapping(CameraInput.CHASECAM_MOVERIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, false));
    } else {
        inputManager.addMapping(CameraInput.CHASECAM_MOVELEFT, new MouseAxisTrigger(MouseInput.AXIS_X, false));
        inputManager.addMapping(CameraInput.CHASECAM_MOVERIGHT, new MouseAxisTrigger(MouseInput.AXIS_X, true));
    }
}
 
Example #29
Source File: ChaseCameraAppState.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void initVerticalAxisInputs() {
    if (!invertYaxis) {
        inputManager.addMapping(CameraInput.CHASECAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
        inputManager.addMapping(CameraInput.CHASECAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
    } else {
        inputManager.addMapping(CameraInput.CHASECAM_DOWN, new MouseAxisTrigger(MouseInput.AXIS_Y, false));
        inputManager.addMapping(CameraInput.CHASECAM_UP, new MouseAxisTrigger(MouseInput.AXIS_Y, true));
    }
}
 
Example #30
Source File: LwjglWindow.java    From jmonkeyengine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public MouseInput getMouseInput() {
    if (mouseInput == null) {
        mouseInput = new GlfwMouseInput(this);
    }
    return mouseInput;
}